Created
November 27, 2017 14:43
-
-
Save azamsharp/1e8972ad89943422f4cced103f730bff to your computer and use it in GitHub Desktop.
SourceListViewModel and SourceViewModel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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