• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Swift: Any way to extract the bound "self" from a closure?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Swift: Any way to extract the bound "self" from a closure?


  • Subject: Re: Swift: Any way to extract the bound "self" from a closure?
  • From: Rick Mann <email@hidden>
  • Date: Fri, 24 Oct 2014 18:00:33 -0700

> On Oct 24, 2014, at 17:57 , Kyle Sluder <email@hidden> wrote:
>
> On Oct 24, 2014, at 5:24 PM, Rick Mann <email@hidden> wrote:
>>
>> 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)?
>
> Imagine there were a keyword that allowed this. What would it evaluate to if the caller *didn’t* pass in a method, but rather a pure closure?
>
> --Kyle Sluder

Well, I guess I could imagine this:

    if let theFoo = inFunc.self as Foo
    {
        theFoo.doSomethingElseOnFoo();
    }

--
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


References: 
 >Swift: Any way to extract the bound "self" from a closure? (From: Rick Mann <email@hidden>)
 >Re: Swift: Any way to extract the bound "self" from a closure? (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Re: Swift: Any way to extract the bound "self" from a closure?
  • Next by Date: Any way to avoid external parameter names?
  • Previous by thread: Re: Swift: Any way to extract the bound "self" from a closure?
  • Next by thread: Any way to avoid external parameter names?
  • Index(es):
    • Date
    • Thread