nsoperationqueue

Waiting for multiple blocks to finish

 ̄綄美尐妖づ 提交于 2019-12-02 19:29:12
I have those methods to retrieve some object information from the internet: - (void)downloadAppInfo:(void(^)())success failure:(void(^)(NSError *error))failure; - (void)getAvailableHosts:(void(^)())success failure:(void(^)(NSError *error))failure; - (void)getAvailableServices:(void(^)())success failure:(void(^)(NSError *error))failure; - (void)getAvailableActions:(void(^)())success failure:(void(^)(NSError *error))failure; The downloaded stuff gets stored in object properties, so that is why the success functions return nothing. Now, I want to have one method like this: - (void)syncEverything:

NSOperationQueue mainQueue vs performSelectorOnMainThread?

独自空忆成欢 提交于 2019-12-02 19:01:21
What's the difference between this: [[NSOperationQueue mainQueue] addOperationWithBlock:^{ [self doSomthing:object]; }]; and this: [self performSelectorOnMainThread:@selector(doSomething:) withObject:object waitUntilDone:NO] Mike Z [self performSelectorOnMainThread:@selector(doSomething:) withObject:object waitUntilDone:NO] Will perform the selector right when it is called. This is what you have to use if you want to affect the UI from a background thread. If you say YES to waitUntilDone it will block the thread until the method has completed. mainQueue adds that block to the operation queue

How is it possible to perform multiple Alamofire requests that are finished one after another?

故事扮演 提交于 2019-12-02 17:33:35
问题 I would like to perform multiple Alamofire requests. However, because of data dependency a new request should only start when the previous is finished. I already asked a question with a more general example of an asynchronous request which was solved with OperationQueue . However, I do not succeed to achieve the same with Alamofire. public func performAlamofireRequest(_ number: Int, success: @escaping (Int) -> Void)->Void { Alamofire.request(String(format: "http://jsonplaceholder.typicode.com

Which is the best of GCD, NSThread or NSOperationQueue? [closed]

纵饮孤独 提交于 2019-12-02 16:19:46
What's the best way of multithreading in iOS as we have three options GCD, NSThread , and NSOperationQueue ? I am confused in which one is the best? If none, then which should be used in what scenario and how they differ and also, if someone has some good example of using NSOperationQueue , please share so that I can learn. Simple answer: Use NSThread (or even the pthreads API) when you want or need to have direct control over the threads you create, e.g. you need fine-grained control over thread priorities or are interfacing with some other subsystem that vends/consumes thread objects

Learning NSBlockOperation

隐身守侯 提交于 2019-12-02 15:55:55
I'm a big fan of blocks, but have not used them for concurrency. After some googling, I pieced together this idea to hide everything I learned in one place. The goal is to execute a block in the background, and when it's finished, execute another block (like UIView animation)... - (NSOperation *)executeBlock:(void (^)(void))block completion:(void (^)(BOOL finished))completion { NSOperation *blockOperation = [NSBlockOperation blockOperationWithBlock:block]; NSOperation *completionOperation = [NSBlockOperation blockOperationWithBlock:^{ completion(blockOperation.isFinished); }];

How is it possible to perform multiple Alamofire requests that are finished one after another?

不羁的心 提交于 2019-12-02 08:47:49
I would like to perform multiple Alamofire requests. However, because of data dependency a new request should only start when the previous is finished. I already asked a question with a more general example of an asynchronous request which was solved with OperationQueue . However, I do not succeed to achieve the same with Alamofire. public func performAlamofireRequest(_ number: Int, success: @escaping (Int) -> Void)->Void { Alamofire.request(String(format: "http://jsonplaceholder.typicode.com/posts/%i", number+1)) // NSURLSession dispatch queue .responseString { response in // Completion

NSOperation and NSURLConnection mystified

一世执手 提交于 2019-12-02 03:23:11
I am trying to download multiple images from some server using NSOperation and NSOperationQueue. My main question is what is the difference between the code snippet below, and this link http://www.dribin.org/dave/blog/archives/2009/05/05/concurrent_operations/ , performance wise? I prefer the second solution, because we have a lot more control over the operations, it is a lot cleaner, and if a connection fails you can handle it properly. If I try to download about 300 images from a server with the code below, my app will have a pretty big delay, and if I launch the app, and go to the home

NSOperation and NSURLConnection mystified

醉酒当歌 提交于 2019-12-02 03:20:26
问题 I am trying to download multiple images from some server using NSOperation and NSOperationQueue. My main question is what is the difference between the code snippet below, and this link http://www.dribin.org/dave/blog/archives/2009/05/05/concurrent_operations/, performance wise? I prefer the second solution, because we have a lot more control over the operations, it is a lot cleaner, and if a connection fails you can handle it properly. If I try to download about 300 images from a server with

Dispatch Group inside NSOperation - Still allowing multiple operations despite maxConcurrentOperationCount = 1

百般思念 提交于 2019-12-02 02:49:31
问题 I am aiming for a serial download queue within NSOperation subclass using dispatch groups to manage async tasks. I have maxConcurrentOperationCount set to 1 i have defined my queue var GlobalDownloadQueue: DispatchQueue { return DispatchQueue.global(qos: DispatchQoS.QoSClass.background) } Then inside main() of NSOperation subclass i have defined my dispatch group, have 3 enters and 3 leaves, then a notify block. The notify block seems to be running at the right time, however there is still

Dispatch Group inside NSOperation - Still allowing multiple operations despite maxConcurrentOperationCount = 1

喜夏-厌秋 提交于 2019-12-02 00:41:29
I am aiming for a serial download queue within NSOperation subclass using dispatch groups to manage async tasks. I have maxConcurrentOperationCount set to 1 i have defined my queue var GlobalDownloadQueue: DispatchQueue { return DispatchQueue.global(qos: DispatchQoS.QoSClass.background) } Then inside main() of NSOperation subclass i have defined my dispatch group, have 3 enters and 3 leaves, then a notify block. The notify block seems to be running at the right time, however there is still multiple instances of the NSOperation running at once. This is what the console is printing when i select