Created
April 8, 2023 19:31
-
-
Save naturalwarren/2003d13b36f3967993e03d3165920cfa to your computer and use it in GitHub Desktop.
SDUIComponent Helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension SDUIComponent { | |
private var concreteModel: Any { | |
switch self { | |
case .button(let button): | |
return button | |
case .row(let row): | |
return row | |
case .text(let text): | |
return text | |
} | |
} | |
func viewModel(context: SDUIContext) -> ViewModel? { | |
if let concreteModel = concreteModel as? ViewModelConvertible { | |
return concreteModel.viewModel(context: context) | |
} else { | |
assertionFailure("This component is not supported") | |
return nil | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment