#import "ViewController.h"
typedef void (^myBlock)(int );
@interface ViewController ()
@property (strong, nonatomic) IBOutlet UIView *testView;
@end
@implementation ViewController
- (IBAction)blockTest:(id)sender
{
[self blockRecursion:0];
}
- (void)blockRecursion:(NSInteger)n
{
__weak myBlock __block block = ^(int bn)
{
NSLog(@"%d", bn);
if(bn < 10)
{
[self getData:block num:++bn];
}
};
block(0);
}
- (void)getData:(myBlock)block num:(NSInteger)bn
{
self.testView.alpha = 1;
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.testView.alpha = 0;
} completion:^(BOOL finished) {
block(bn);
}];
}
@end
运行崩溃:错误:地址不包含指向目标文件中的节的节
__weak myBlock __block block = ^(int bn);
//Changed to
myBlock __block block = ^(int bn);
显示警告:在此块中强烈捕获“块”可能会导致保留周期
如何解决这个问题呢?