> On Jan 1, 2015, at 18:26, Graham Cox <[email protected]> wrote: > > >> On 2 Jan 2015, at 12:48 pm, Quincey Morris >> <[email protected]> wrote: >> >> **** That usually means the block and the ‘self’ it captured mutually refer >> to each other. I’m betting this is what’s wrong in your case. >> >> > > > Quincey, thanks for your lengthy and well-thought-out reply (as usual) :) > > I think you've hit the nail straight on the head (as usual), with the > block/self problem. It's one I knew about before, but had forgotten again in > my excitement at getting the code running. The question is what to do about > it. > > My handler block refers to 'self' quite extensively - it calls other methods > of self and also refers to properties such as self.delegate. I'm not quite > sure how I can rework it not to refer to self. Maybe I just need to not use > the completion block approach and use a delegate callback instead. I need to > go away and think about this... thanks for the slap about the head. > > —Graham
One of the first things I define in any ARC codebase I’m going to be working on
is:
#define DECLARE_WEAK_SELF __weak __typeof__(self) weak_self = self;
#define DECLARE_STRONG_SELF __strong __typeof__(weak_self) self = weak_self;
And I use it like so:
- (void)method {
DECLARE_WEAK_SELF
self.someBlock = ^{
DECLARE_STRONG_SELF;
//Use “self” as usual here
};
self.someOtherBlock = ^{
DECLARE_STRONG_SELF;
//Use “self” as usual here
};
}
--
Clark Smith Cox III
[email protected]
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Cocoa-dev mailing list ([email protected]) 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 [email protected]
