当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - Retain cycle warning inside block

问题描述:

Accessing the dictionary allData after completion of NSInvocationOperation triggers a retain cycle warning:

operationQueue = [[NSOperationQueue alloc]init];

invocationOperation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(loadDataAsychn) object:nil];

[operationQueue addOperation:invocationOperation];

invocationOperation.completionBlock = ^(void) {

for(NSDictionary *dict in allData)

{

[imgArr addObject:[dict objectForKey:@"image"]];

[urlArr addObject:[dict objectForKey:@"url"]];

}

dispatch_async(dispatch_get_main_queue(), ^{

[NSTimer scheduledTimerWithTimeInterval:5.0

target:self

selector:@selector(targetMethod:)

userInfo:imgArr

repeats:YES];

});

};

-(void)loadDataAsychn

{

NSString *imgStr = [NSString stringWithFormat:@"%@/url",urlconstant];

NSData *imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:imgStr]];

allData = [NSJSONSerialization JSONObjectWithData:imageData

options:0

error:nil];

}

分享给朋友:
您可能感兴趣的文章:
随机阅读: