Monday, 19 August 2013

Block stored as instance variable becomes nil

Block stored as instance variable becomes nil

I'm trying to store a block in an instance variable in my project. Here's
where I declare the instance variable:
@property (nonatomic, copy)void (^loginCompletedTask)();
I'm assigning the variable by calling this method:
- (void)requireLoggedInForBlock:(void (^)())completion {
self.loginCompletedTask = completion;
// Display an alert view that requires username and password input
}
After the first line of this method, self.loginCompletedTask is non-nil
and logs in the debugger with type NSMallocBlock. However, when I actually
need to run the block after the login alert view is returned, it has
become nil.
I've tried:
Declaring with strong instead of copy,
Setting as self.loginCompletedTask = ^{completion();};,
Setting the variable directly, instead of using a property
(_loginCompletedTask = ...).
What am I missing?

No comments:

Post a Comment