Multithreading in iOS| Difference between GCD and NSOperation

Basics of concurrency in iOS.

Abhimuralidharan
5 min readNov 17, 2017

Threading is an important concept in iOS. The concept is pretty simple. This is what happens inside the processor. Consider launching an app in your iPhone. When the app launches, it will be on the main thread or the UI thread. At this point, when we try to do some time consuming task in the main thread, the UI will stop responding for a while. This is a situation the user will never want to face. From the users perspective, the app should always be responding and should be fast. As we know , most of the modern processors supports multitasking and are pretty fast. So, instead of doing the time consuming task in the main thread, better give it to different thread so that the main thread can do the other work it has to perform.

Consider an example of loading a tableview . You will be calling a method which takes some time say 5 seconds to return with the data for tableview and you will be doing this in the viewDidLoad().

override func viewDidLoad() {super.viewDidLoad()doSomeTimeConsumingTask() // takes 5 seconds to respond
tableView.reloadData()
}

The execution happens line by line and when doSomeTimeConsumingTask() method is called, the UI…

--

--