Created
March 27, 2017 16:54
-
-
Save JohnSundell/bcdb4fd5767c74757f1a99fc123e6ef3 to your computer and use it in GitHub Desktop.
Code sample #5 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 AnyModelLoader<T>: ModelLoading { | |
typealias CompletionHandler = (Result<T>) -> Void | |
private let loadingClosure: (CompletionHandler) -> Void | |
init<L: ModelLoading>(loader: L) where L.Model == T { | |
loadingClosure = loader.load | |
} | |
func load(completionHandler: CompletionHandler) { | |
loadingClosure(completionHandler) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment