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)

Common iOS Development Interview Questions

A learning route for iOS developers

1 What is a block

There are many definitions for a closure (block), where a closure is a function that can read the internal variables of another function. This definition is both close to the core and easy to understand. For those of you who are new to blocks, this is a little confusing, because we’re used to writing programs like main(){funA(); } funA(){funB(); } funB(){….. }; So function main calls function A, function A calls function B… Function in turn order, but the reality is not complete, such as project manager of M, under three programmers A, B, C, when he give the programmer A arrangement function F1, he did not wait for A finished, and then to arrange B to achieve F2, but to A function F1, F2, B function F3 C function, and then may go to write technical documentation, When A has A problem, he will come to M, the project manager, and when B is done, he will notify M. This is an example of asynchronous execution. In this case, Block can lead, because in the project manager of M, make arrangements for A job, at the same time will tell if A meet with difficulties, how to find his report problems (e.g., call his cell phone number), this is A project manager M for A A callback interface, to back off the operation, such as received A phone call, after baidu query, return to the web page content to A, This is A Block, which has been defined when M explains the work and obtains the task number (local variable) of F1. However, it is called and executed only when A encounters A problem. The cross-function calls the Block after the project manager M queries Baidu and obtains the result.

Objective-c is an extension of the C language. The implementation of blocks is based on Pointers and function Pointers. From the development of computing language, the earliest GOto, the pointer of high-level language, to the block of object-oriented language, from the thinking of machine, step by step close to the thinking of human, in order to facilitate developers to describe the realistic logic (requirements) more efficiently and directly. Here are two good blog posts about the block implementation

Exploration of block implementation in iOS

3 Use of block

Using the instance

UIView using Animation control Animation

Use typed to declare blocks

typedef void(^didFinishBlock) (NSObject *ob);

So that declares a block of type didFinishBlock,

And then you can use it

@property (nonatomic,copy) didFinishBlock finishBlock; Declare a block object. Note that the object property is set to copy. When a block parameter is received, a copy is automatically made.

__block is a special type,

The local variable declared with this keyword can be changed by the block, and its value in the original function will be changed.

In an interview, the interviewer will ask you if you know about blocks and if you have used blocks. These are the opening questions and usually the beginning of a series of questions, so be sure to answer them according to your situation.

What are the advantages of using block versus delegate mode? So the first thing to understand is what delegate pattern is, delegate pattern is used a lot in iOS, it’s used in design mode as an object adapter pattern, and objective-C uses the ID type to point to everything, which makes it easier to implement delegate pattern in iOS. Learn the details of the delegate pattern:

IOS Design mode — Delegate mode

Multithreading with blocks

The GCD and Block

Using the dispatch_async series of methods, you can execute blocks in a specified manner

The GCD programming

Full definition of dispatch_async

void dispatch_async(

dispatch_queue_t queue,

dispatch_block_t block);

Function: commit a block asynchronously in the specified queue without blocking the current thread

The queue controls the thread of execution of the block. The main thread executes the finishBlock object defined above dispatch_async(dispatch_get_main_queue(),^(void){finishBlock(); });