Skip to content

Instantly share code, notes, and snippets.

@mecid
Last active January 8, 2018 12:21
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/e82817ce465c896e6655f32b2adac8c6 to your computer and use it in GitHub Desktop.
Save mecid/e82817ce465c896e6655f32b2adac8c6 to your computer and use it in GitHub Desktop.
Mastering MVVM
import Foundation
class ItemsViewModel {
var items: [Item] = []
var error: Error?
var refreshing = false
private let dataManager: DataManager
init(dataManager: DataManager) {
self.dataManager = dataManager
}
func fetch(completion: @escaping () -> Void) {
refreshing = true
dataManager.fetchItems { [weak self] (items, error) in
self?.items = items ?? []
self?.error = error
self?.refreshing = false
completion()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment