Skip to content

Instantly share code, notes, and snippets.

Created October 19, 2015 21:57
Show Gist options
  • Save anonymous/1e95d3276cd562d4d23a to your computer and use it in GitHub Desktop.
Save anonymous/1e95d3276cd562d4d23a to your computer and use it in GitHub Desktop.
Method Chaining
// 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