IOS Interview Questions:

IOS Interview Collection + Answer (1)

IOS Interview Collection + Answer (2)

IOS Interview Collection + Answer (3)

IOS Interview Collection + Answer (4)

IOS Interview Collection + Answers (5)

IOS Advanced interview questions —-Block

1 What is multithreading

Multithreading is a complex concept, according to the literal meaning is the synchronization to complete various tasks, improve the efficiency of the use of resources, from the hardware, operating system and application software to see a different point of view, a multithreaded are endowed with different meaning, for hardware, now on the market most of the CPU are multicore, multi-core CPU operation multithreaded better; In terms of operating systems, it’s multitasking. The mainstream operating systems are multitasking. You can listen to music and write a blog at the same time. For applications, multi-threading makes them more responsive and can be downloaded over the network in response to user touch. In iOS applications, the initial understanding of multithreading is concurrency, which means that the original work of boiling water first, then picking vegetables, and then cooking vegetables, will become boiling water at the same time to pick vegetables, and then cooking vegetables.

2. Multithreading in iOS

The multithreading, iOS is multithreaded, under the framework of the Cocoa by Cocoa encapsulation, can make us more convenient in the use of threads, worked in c + + classmates threads is likely to have more understanding, such as thread creation, semaphores, and Shared variables are known, the Cocoa framework will be more convenient, it gave an encapsulation, the thread some encapsulation, This allows us to create objects that have threads of their own, objectification of threads, thereby reducing the robustness of our project provider.

GCD, short for Grand Central Dispatch, is an easy-to-use multithreaded class library provided at the system level with runtime features that take full advantage of multi-core hardware. The API interface of GCD is the function of C language, and most of the function parameters have blocks. See here for the use of blocks, which provides a powerful “interface” for us. See this article for the use of GCD

NSOperation and Queue

NSOperation is an abstract class that encapsulates the details of the implementation of threading. We can manage multithreaded programs with object-oriented thinking by subclassing this object and adding NSQueue. See here: a multi-threaded Network access project based on NSOperation.

NSThread

NSThread is an object that controls the execution of a thread. It’s less abstract than NSOperation, so it’s easy to get a thread and control it. But the concurrency control between nsThreads, we need to control ourselves, can be implemented through NSCondition. See the use of nsThreads in iOS multithreaded programming

Other multithreading

In the Framework of Cocoa, notifications, timers and asynchronous functions all use multithreading (to be added).

3 iOS multithreading often meet questions

When do you choose to use GCD in a project and when do you choose NSOperation? The advantage of using NSOperation in a project is that NSOperation is a high abstraction of threads. Using NSOperation in a project will make the program structure of the project better. The design idea of subclassing NSOperation has the advantages of object-oriented (reuse, encapsulation), which makes the implementation support multi-threading, and the interface is simple. Recommended for complex projects. The advantage of using GCD in a project is that GCD itself is very simple and easy to use. For non-complex multi-threaded operations, it will save the amount of code, and the use of Block parameter will make the code more readable, so it is recommended to use it in a simple project.

Bonus: a learning route reference for iOS developers