Yes, this is jumping through hoops, and even then you are not entirely safe. 
How about referencing ivars from blocks? How about referencing other objects 
that may in their turn reference self etc.? You have to keep it all in mind and 
constantly fight with the side-effects by adding more crappy hoops to your 
code. And it is a problem that does not even exist with delegates. 

On Apr 25, 2013, at 8:29 PM, Jens Alfke <j...@mooseyard.com> wrote:

> 
> On Apr 25, 2013, at 9:54 AM, Lee Ann Rucker <lruc...@vmware.com> wrote:
> 
>> MyWeakRef *weakRef = [MyWeakRef weakRefFromObject:self];
>> 
>> ^() = {
>>  Foo *wself = [weakRef originalObject];
>>  // wself may be nil, that's cool because we only want to doStuff if 'self' 
>> is still around.
>>  [wself doStuff];
>> }
> 
> It's easier to just use the __weak attribute, if you're using ARC:
> 
> __weak Foo *weakRef = self;
> ^() = {
>       Foo *wself = weakRef;
>       // wself may be nil, that's cool because we only want to doStuff if 
> 'self' is still around.
>       [wself doStuff];
> }
> 
> Still, I think this is what Oleg called "jumping through hoops". You and I 
> just don't think it's a very significant hoop :)
> 
> —Jens
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to