Managing CPU intensive threads on iOS

前端 未结 4 1334
清歌不尽
清歌不尽 2021-01-05 11:35

I’m an experienced C/C++ programmer coming up to speed on Objective C on the iPhone. I have done a lot of searching, but haven’t found a satisfactory answer on what must be

4条回答
  •  被撕碎了的回忆
    2021-01-05 12:08

    I'd have a model object that does the CPU tasks, which has a delegate callback for when the output changes, and a view controller. In viewDidLoad you set the view controller as the delegate of your model. The model, therefore, can use threads and sends messages back on the main queue, when the calculated data has been updated. Unless your case is specifically complex, is just use Grand Central Dispatch and dispatch_async the intensive task onto another thread.

    Certainly, you should not be calling sleepForTimeInterval anywhere to achieve what you want.

提交回复
热议问题