Multithreading in iOS-Part 4/4

If task is not started, then this will be canceled else task can’t be cancelled instead it will set isCancelled value to true.

in iOS, all views are display and animate by Core Animation Framework, not UIKit.

Vertical Sync (VSYNC): This signal is transmitted after the entire frame is transferred. This signal is often a way to indicate that one entire frame is transmitted.

These two framework are not actually update UI on background threads, instead it use some time-consuming operations asynchronously, bypassing the limitation that UI can only be updated on the main thread.

Run Loop and View Drawing Cycle

1. get current runloop and 2. Get main runloop

Although removing a run loop’s input sources and timers may also cause the run loop to exit, this is not a reliable way to stop a run loop.

This is because consider example that some system routines add input sources to a run loop to handle events, during this time your run loop will not exit because your code might not be aware of these input source.

The run method of UIApplication in iOS (or NSApplication in OS X) starts an application’s main loop as part of the normal startup sequence. These methods will run the main threads runloop automatically.

You can define custom modes by specifying a custom string for the mode name.

You must be sure to add one or more input sources, timers, or run-loop observers to any modes you create to use them.

In addition to port-based sources, Cocoa defines a custom input source that allows you to perform a selector on any thread. Like a port-based source, perform selector requests are serialised on the target thread. Perform selector source removes itself from the run loop after it performs its selector.

create timer in current run loop
create a runloop within the thread

It’s not thread-safe. Don’t call the methods of a NSRunLoop object running in a different thread, which might cause unexpected results.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store