Skip to content

Instantly share code, notes, and snippets.

@mecid
Last active January 8, 2018 19:47
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 mecid/33784e19bb191b5d552570eb5ef9b4d7 to your computer and use it in GitHub Desktop.
Save mecid/33784e19bb191b5d552570eb5ef9b4d7 to your computer and use it in GitHub Desktop.
Mastering MVVM
import Bond
class ItemsViewModel {
let items = Observable<[Item]>([])
let error = Observable<Error?>(nil)
let refreshing = Observable<Bool>(false)
private let dataManager: DataManager
init(dataManager: DataManager) {
self.dataManager = dataManager
}
func fetch() {
refreshing.value = false
dataManager.fetchItems { [weak self] (items, error) in
self?.items.value = items ?? []
self?.error.value = error
self?.refreshing.value = false
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment