Skip to content

Instantly share code, notes, and snippets.

@Blightwidow
Last active February 23, 2018 14:05
Show Gist options
  • Save Blightwidow/6169fd2d8acd230e06c4ac216fff9aad to your computer and use it in GitHub Desktop.
Save Blightwidow/6169fd2d8acd230e06c4ac216fff9aad to your computer and use it in GitHub Desktop.
MVVM ViewModel
class accountViewModel {
// MARK: Interfaces
private var date: Date = Date() {
didSet {
DispatchQueue.main.async {
self.updateDate?(self.date)
}
}
}
var updateDate: ((Date) -> Void)?
// MARK: Object lifecycle
init() {
setup()
}
// MARK: View lifecycle
private func setup() {
}
// MARK: Available calls
func fetchDate() {
fetchDateFromApi(completion: { fetchedDate in
guard let date = fetchedDate else { return }
self.date = date
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment