开发者

NSOperationQueue operation priority

I have开发者_StackOverflow中文版 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..


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜