-
-
Save stevencurtis/090effaf3be15fb0a826158b92e622b3 to your computer and use it in GitHub Desktop.
DataManager
This file contains 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 DataManager { | |
private let queueManager: QueueManager | |
init(withQueueManager queueManager: QueueManager = QueueManager.sharedInstance) { | |
self.queueManager = queueManager | |
} | |
func retrieveUserList(completionBlock: @escaping (ListUsersModel?) -> Void) { | |
guard let url = URL(string: Constants.baseURL + "?page=2") else {return} | |
let fetch = UserListRetrievalOperation(url: url, httpManager: HTTPManager(session: URLSession.shared)) | |
let parse = UserListDecodeOperation() | |
// use an adapter to pass the data from fetch to parse | |
let adapter = BlockOperation() { [unowned fetch, unowned parse] in | |
parse.dataFetched = fetch.dataFetched | |
parse.error = fetch.error | |
} | |
adapter.addDependency(fetch) | |
parse.addDependency(adapter) | |
parse.completionHandler = {data in | |
completionBlock(data) | |
} | |
queueManager.addOperations([fetch, parse, adapter]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment