nscondition

Waiting on asynchronous methods using NSCondition

纵然是瞬间 提交于 2019-12-24 00:58:09
问题 I am downloading four plist files asynchronously over the internet. I need to wait until all four files are downloaded, until I either on the first run, push a UIViewController, or on all subsequent runs, refresh the data, and reload all my UITableViews. On the first run, everything works perfectly. When refreshing though, all four url requests are called, and started, but never call their completion or failure blocks, and the UI freezes. Which is odd since I preform all operations in a

Thread-safe access to a datasource during a tableView update

我们两清 提交于 2019-12-11 13:37:16
问题 My app uses a tableView with a data source that can be updated asynchronously by multiple threads. When the data source is changed, the tableView is updated, not reloaded, using tableView.performBatchUpdates({ tableView.deleteRows(at: deletions, with: .automatic) tableView.insertRows(at: insertions, with: .automatic) for (from, to) in movements { tableView.moveRow(at: from, to: to) } }, completion: { (finished) in if !finished { self.tableView.reloadData() } else { // some cleanup code }

Pause Main thread until background thread retrieves user input

孤街浪徒 提交于 2019-12-10 11:45:19
问题 In my main starting thread I need to pause the code and start a new thread and wait until I get user input. Then Id like to discard the new thread made and go back to where the main thread left off. But whats happening is that the new thread is called but the main thread keeps going with the code. How do I deal with this without interfering with the user being able to use the interface buttons? I think that maybe another nscondition needs to be made in my if(moveCount == 2) statement? Or that

Pause Main thread until background thread retrieves user input

半腔热情 提交于 2019-12-06 16:06:20
In my main starting thread I need to pause the code and start a new thread and wait until I get user input. Then Id like to discard the new thread made and go back to where the main thread left off. But whats happening is that the new thread is called but the main thread keeps going with the code. How do I deal with this without interfering with the user being able to use the interface buttons? I think that maybe another nscondition needs to be made in my if(moveCount == 2) statement? Or that my main thread needs to wait for a signal from my other thread notifying user input is received.