Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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