Created
March 27, 2017 16:48
-
-
Save JohnSundell/d6770d6ced11b53c2bf954bf2e4547bf to your computer and use it in GitHub Desktop.
Code sample #1 from https://medium.com/@johnsundell/type-erasure-using-closures-in-swift-1e6125231f8
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 ModelLoader<T: Unboxable & Requestable> { | |
func load(completionHandler: (Result<T>) -> Void) { | |
networkService.loadData(from: T.requestURL) { data in | |
do { | |
try completionHandler(.success(unbox(data: data))) | |
} catch { | |
let error = ModelLoadingError.unboxingFailed(error) | |
completionHandler(.error(error)) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment