NSOperationQueue 操作优先级
我的操作有问题。当我向 NSOperationQueue 添加操作并且它已执行时,我有一个添加到数组结果的方法。这是我的方法:
- (void)loadPostImageWithDictionary:(NSDictionary*)dict
{
NSData *tmpImageData = [[NSData alloc] initWithContentsOfURL:
[NSURL URLWithString: [dict
objectForKey:@"picture"]]];
UIImage *image=[[UIImage alloc] initWithData:tmpImageData];
[userPostImage addObject:image];
[image release];
}
如果某些操作已提前执行 - 将结果添加到数组中。但我需要按照我添加操作的顺序执行操作。请帮忙..
I have a problem with operations. When I add operations to NSOperationQueue and it's had executed I have a method that add to array result. This is my method:
- (void)loadPostImageWithDictionary:(NSDictionary*)dict
{
NSData *tmpImageData = [[NSData alloc] initWithContentsOfURL:
[NSURL URLWithString: [dict
objectForKey:@"picture"]]];
UIImage *image=[[UIImage alloc] initWithData:tmpImageData];
[userPostImage addObject:image];
[image release];
}
And if some operation have executed early - result adding to array. But I need that the operations were performed in the order of which I added them. Please help..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 [NSOperationQueue setMaxConcurrentOperationCount:1] 方法一次只允许运行一个操作,从而有效地在另一个线程上创建一个串行队列。
如果您的代码依赖于以特定顺序运行的操作(在多线程中,这首先并不是一个很好的设计),那么为什么不将一组字典传递给单个操作,该操作会下载所有图像并在委托方法中返回图像数组?
use
[NSOperationQueue setMaxConcurrentOperationCount:1]
method to only allow one operation to run at a time, effectively making a serial queue on another thread.if your code depends on operations running in a specific order (which, in multithreading, isn't really good design in the first place), when why don't you just pass an array of dictionaries to a single operation, that downloads all the images and returns the array of images in a delegate method?