Skip to content

Instantly share code, notes, and snippets.

@azamsharp
Created November 27, 2017 14:43
Show Gist options
  • Save azamsharp/1e8972ad89943422f4cced103f730bff to your computer and use it in GitHub Desktop.
Save azamsharp/1e8972ad89943422f4cced103f730bff to your computer and use it in GitHub Desktop.
SourceListViewModel and SourceViewModel
class SourceListViewModel : NSObject {
private(set) var sourceViewModels :[SourceViewModel] = [SourceViewModel]()
private var webservice :Webservice
init(webservice :Webservice) {
self.webservice = webservice
super.init()
// call populate sources
populateSources()
}
func populateSources() {
self.webservice.loadSources { [unowned self] sources in
self.sourceViewModels = sources.flatMap(SourceViewModel.init)
}
}
}
// SourceViewModel
class SourceViewModel : NSObject {
var id :String?
var name :String
var body :String
init(name :String, description: String) {
self.name = name
self.body = description
}
init(source :Source) {
self.id = source.id
self.name = source.name
self.body = source.description
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment