NSOperation and NSOperationQueue working thread vs main thread

后端 未结 6 2013
心在旅途
心在旅途 2020-11-28 01:00

I have to carry out a series of download and database write operations in my app. I am using the NSOperation and NSOperationQueue for the same.

6条回答
  •  萌比男神i
    2020-11-28 01:52

    From NSOperationQueue

    In iOS 4 and later, operation queues use Grand Central Dispatch to execute operations. Prior to iOS 4, they create separate threads for non-concurrent operations and launch concurrent operations from the current thread.

    So,

    [NSOperationQueue mainQueue] // added operations execute on main thread
    [NSOperationQueue new] // post-iOS4, guaranteed to be not the main thread
    

    In your case, you might want to create your own "database thread" by subclassing NSThread and send messages to it with performSelector:onThread:.

提交回复
热议问题