Skip to content

Instantly share code, notes, and snippets.

@Vadim-Yelagin
Created September 28, 2015 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vadim-Yelagin/9d03459415d3ab7c8eba to your computer and use it in GitHub Desktop.
Save Vadim-Yelagin/9d03459415d3ab7c8eba to your computer and use it in GitHub Desktop.
import Foundation
func invocation<C: AnyObject, In, Out>
(target target: C, method: C -> In -> Out)
-> In -> Out?
{
return {
[weak target] input in
if let target = target {
return method(target)(input)
} else {
return nil
}
}
}
class Boo {
func foo(input: Int) -> String {
return "Foo \(input)"
}
}
let boo = Boo()
let inv = invocation(target: boo, method: Boo.foo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment