Created
October 19, 2015 21:57
-
-
Save anonymous/1e95d3276cd562d4d23a to your computer and use it in GitHub Desktop.
Method Chaining
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
// MARK: Method chaining | |
class MethodChainig { | |
func fetchImage() -> Fetch<UIImage> { | |
let fetch = Fetch<UIImage>() | |
return fetch | |
} | |
} | |
class Fetch<T> { | |
func onSuccess(succeed : T -> ()) -> Self { | |
return self | |
} | |
func onFailure(fail : NSError? -> ()) -> Self { | |
return self | |
} | |
} | |
let example4 = MethodChainig() | |
example4.fetchImage().onSuccess { image in | |
// success | |
} | |
example4.fetchImage().onFailure { error in | |
// Failure | |
}.onSuccess { image in | |
// Success | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment