nsoperation

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:

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); }];

Undoing Core Data insertions that are performed off the main thread

陌路散爱 提交于 2019-12-02 14:57:51
I'm working on some code that uses an NSOperation to import data. I'd like for the user to be able to undo the NSManagedObject instances that are created during the import operation. From what I can tell, it's impossible to use the NSManagedObjectContext -undoManager for any operations that are performed off of the main thread. From the Core Data Programming Guide section on Use Thread Confinement to Support Concurrency , we have these two conditions: Only objectID should be passed between managed object contexts (on separate threads) Managed objects must be saved in a context before the

NSOperation performance

女生的网名这么多〃 提交于 2019-12-02 08:21:05
I am trying to server side connection on a background thread using NSOperation. I didn't want to subclass NSOperation ..So how can use NSOperation and how to return response from NSOperation... Any Ideas about this? since NSOperation is an abstract class there is no way to use NSOperation without using a subclass of NSOperation. If you don't want to subclass yourself you can use one of the NSOperation subclasses (ie NSInvocationOperation , or NSBlockOperation ). Here is a good example where to start: Cocoa Tutorial: NSOperation and NSOperationQueue 来源: https://stackoverflow.com/questions

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

Operation went isFinished=YES without being started by the queue it is in

孤人 提交于 2019-12-01 11:42:28
Overview There is an asynchronous operation subclass Added this operation to the queue. I cancelled this operation before it starts. Runtime Error / Warning: SomeOperation went isFinished=YES without being started by the queue it is in Question: Is this something that can be ignored or it is something serious ? How to resolve this ? Is the workaround / solution provided at the end valid ? Code: public class SomeOperation : AsyncOperation { //MARK: Start public override func start() { isExecuting = true guard !isCancelled else { markAsCompleted() //isExecuting = false, isFinished = true return

Operation went isFinished=YES without being started by the queue it is in

Deadly 提交于 2019-12-01 09:54:28
问题 Overview There is an asynchronous operation subclass Added this operation to the queue. I cancelled this operation before it starts. Runtime Error / Warning: SomeOperation went isFinished=YES without being started by the queue it is in Question: Is this something that can be ignored or it is something serious ? How to resolve this ? Is the workaround / solution provided at the end valid ? Code: public class SomeOperation : AsyncOperation { //MARK: Start public override func start() {