NSOperation and NSNotificationCenter on the main thread

后端 未结 4 1633
挽巷
挽巷 2020-12-12 23:02

I have an NSOperation. When it is finished I fire a NSNotificationCenter to let the program know that the NSoperation is finished and to update the gui.

To my under

4条回答
  •  鱼传尺愫
    2020-12-12 23:37

    If you're on 10.6, you can also use setCompletionBlock:. It's used like this:

    NSOperation*op= .... ;
    [op setCompletionBlock:^{
        dispatch_async(dispatch_get_main_queue(),^{
            code to be run on the main thread after the operation is finished.
        });
    }];
    

    For general introduction on blocks and GCD, this article was extremely helpful. I found GCD & setCompletionBlock easier to read than NSNotification. One caveat is, well, it only runs on 10.6!

提交回复
热议问题