Swift Tips and Best Practice
Multi threading pro tips
Do not use this for network request. Because it is synchronized and it may block your UI a tens of seconds.
It's the main thread run()
- Handle UI Input
- View Drawing
You have 17ms to do stuff in the main thread.
If you want to some intensive computation. Use another thread.
old method Clumsy and poor. Do not use.
Grand Central Dispatch
- Abstract thread pool pattern
- Better performance
Do not pass objects between threads
Instead, use an observer. Send notification when the object is updated in the sub-thread, then in the main thread, subscribe to the notification, fetch data when got notification.