Using the objc_precise_lifetime attribute ensures the object stays alice to the 
end of the block. 

I think that's a bit better than abusing retain release. 

> On 18 Jul, 2014, at 11:23, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
>> On Jul 17, 2014, at 20:01 , Jens Alfke <j...@mooseyard.com> wrote:
>> 
>> The only thing I’ve found that works is
>>    CFRetain((__bridge CFTypeRef)self);
>> at the top of the method, and a corresponding CFRelease at the end, but this 
>> is pretty ugly
> 
> This seems to be the right way to do it. A CFBridgingRetain/CFBridgingRelease 
> pair may be a slightly prettier way of achieving the same effect.
> 
> It’s always going to be ugly to some degree, because the solution you’re 
> using isn’t the solution to your problem, it just fixes your problem 
> “accidentally" as a side effect.
> 
>> and could cause leaks if the method returns early.
> 
> Perhaps the following pattern would work:
> 
>    - (void) someMethod {
>        CFTypeRef selfRef = CFBridgingRetain (self);
>        @try {
>            doSomeStuff;
>            [self.delegate object: self didSomeStuff: yeah];
>            if (somethingWentWrong)
>                return;
>            doSomeMoreStuff;
>        }
>        @finally {
>            CFBridgingRelease (selfRef);
>        }
>    }
> 
>> Am I missing some convenient way of doing this? I looked through the ARC 
>> docs, at least those I could find, and didn’t see anything relating to this.
> 
> Your real problem is that you don’t have a safe mechanism for ensuring the 
> object’s lifetime. If you solve that, you won’t have to worry about any of 
> the above.
> 
> _______________________________________________
> 
> 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/rols%40rols.org
> 
> This email sent to r...@rols.org

_______________________________________________

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