Contenu connexe
Similaire à Block introduce (20)
Block introduce
- 9. 可修改
id x;
__block id y;
__block BOOL isRuned = NO;
void (^block)(void) =^{
x = [NSString string]; // error
y = [NSString string]; // works
isRuned = YES; //works
};
- 12. 问题
[self setCompletionBlock:^{
NSLog(@"%@", self.error);
}];
self retainCount + 1
self keep completeBlock
- (void)setCompletionBlock:(ASIBasicBlock)aCompletionBlock
{
! [completionBlock release];
! completionBlock = [aCompletionBlock copy];
}
self retain completionBlock, complationBlock retain self
- 13. 解决(without ARC)
__block id that = self;
[self setCompletionBlock:^{
NSLog(@"%@", that.error);
}];
or
NSString *err = self.error;
[self setCompletionBlock:^{
NSLog(@"%@", err);
}];
- 14. 解决(with ARC)
iOS5:
__weak id that = self;
[self setCompletionBlock:^{
NSLog(@"%@", that.error);
}];
iOS4/5:
__unsafe_unretained id that = self;
[self setCompletionBlock:^{
NSLog(@"%@", that.error);
}];
Notes de l'éditeur
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n