Skip to content

Instantly share code, notes, and snippets.

@vantruong1094
Last active May 22, 2019 04:41
Show Gist options
  • Select an option

  • Save vantruong1094/a75cb66bd5b3c8c8ca188bb162cdbd27 to your computer and use it in GitHub Desktop.

Select an option

Save vantruong1094/a75cb66bd5b3c8c8ca188bb162cdbd27 to your computer and use it in GitHub Desktop.
class ItemsViewModel {
var items = DataBinding<[ItemModel]>(value: [])
var error = DataBinding<Error?>(value: nil)
func numberItems() -> Int {
return items.value.count
}
func fetchData() {
ServiceManager.fetchItems { [weak self] (items, error) in
guard let self = self else {return}
if error != nil {
self.error = error
} else {
self.items.value = items
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment