Skip to content

Instantly share code, notes, and snippets.

@naturalwarren
Created April 8, 2023 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naturalwarren/2003d13b36f3967993e03d3165920cfa to your computer and use it in GitHub Desktop.
Save naturalwarren/2003d13b36f3967993e03d3165920cfa to your computer and use it in GitHub Desktop.
SDUIComponent Helper
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