我想返回一组缓存图像。查看代码。我只是想返回我创建的数组,但我不能,dispatch_get_main_queue
而且我不知道如何更改代码以返回数组。我确信这很容易,但我在较低级别的 C / GCD 语法上遇到了困难。谢谢。
-(NSArray *)returnArray
{
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"something" ofType:@"plist"];
NSArray *array = [NSArray arrayWithContentsOfFile:plistPath];
NSMutableArray *finalArray = [[NSMutableArray alloc] initWithCapacity:array.count];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
]
for(int i=0;i<array.count; i++) {
NSString *filePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:[array objectAtIndex:i]];
UIImage *frameImage = [UIImage imageWithContentsOfFile: filePath];
UIGraphicsBeginImageContext(frameImage.size);
CGRect rect = CGRectMake(0, 0, frameImage.size.width, frameImage.size.height);
[frameImage drawInRect:rect];
UIImage *renderedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[finalArray addObject:renderedImage];
}
dispatch_sync(dispatch_get_main_queue(), ^{
//THIS IS WHAT IM TRYING TO DO, BUT I CANT
return finalArray;
});
});
}