Swift: Any way to extract the bound "self" from a closure?
Swift: Any way to extract the bound "self" from a closure?
- Subject: Swift: Any way to extract the bound "self" from a closure?
- From: Rick Mann <email@hidden>
- Date: Fri, 24 Oct 2014 17:24:39 -0700
I discovered a neat property of Swift: Anywhere I can pass a closure, I can also pass a object method (of matching type), and if I reference it from an instance, it captures that instance for the call:
class
Foo
{
func actOnFoo(inValue: Int)
{
}
}
func
neato()
{
var foo: Foo = Foo();
doSomething(foo.actOnFoo);
}
func
doSomething(inFunc: (Int) -> ())
{
}
Inside doSomething(), is it possible to get at inFunc's "self" (in this case, it would be foo)?
--
Rick Mann
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden