完成NSInvocationOperation
后访问字典allData会触发保留周期警告:
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];
}