How to dispatch code blocks to the same thread in iOS?

前端 未结 8 1697
广开言路
广开言路 2021-01-31 11:04

Main aspect of the question: It\'s about iOS. Can I somehow dispatch code blocks in a way, that they will all (a) run in background and (b) on the same thread?

8条回答
  •  无人共我
    2021-01-31 11:17

    You can either use NSOperationQueue with a MaxConcurrentOperationCount of 1 or go the manual way down the road by using NSThread model (rather than Grand Central Dispatch). Using the latter I would recommend you to implement a worker-method which runs in a thread and pulls work-packages (or commands) from a queue or a pool that is being feed from outside of the thread. Just make sure you use Locks / Mutex / Synchronisation.

提交回复
热议问题