Created
September 28, 2015 13:11
-
-
Save Vadim-Yelagin/9d03459415d3ab7c8eba to your computer and use it in GitHub Desktop.
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
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