iOS advanced face question----block section

Source: Internet
Author: User

 iOS advanced face question----block Section 


1 What is block

for closures (blocks), closures are functions that can read other functions ' internal variables.  For example, received the phone, Baidu query, return to the Web content to a, this is a block, in M confessed to work, has been defined, and made F1 task number (local variable), but when a encountered problems, only call execution, cross-function in the project manager m query Baidu, The block is recalled after the result is obtained.  2 Block Implementation principleObjective-c is an extension of the C language, and the implementation of block is based on pointers and function pointers. from the development of computational language, the earliest goto, the pointer to the high-level language, to the object-oriented language block, from the machine's thinking, a step closer to human thinking, in order to facilitate developers more efficient, direct description of the logic of Reality (demand). Here are two great posts to introduce block implementations 3 use of blockworking with Instancesblock invocation of animation effect under Cocoatouch frame use typed to declare blocktypedef void (^didfinishblock) (NSObject *ob);this declares a block of type Didfinishblock,then it will be available@property (nonatomic,copy) didfinishblock Finishblock;declare a BLOKC object, note that the object property is set to copy, and a copy is automatically copied when the block parameter is received.  __block is a special type,a local variable declared with this keyword can be changed by block, and its value in the original function will be changed.   4 Common series of questionsinterview, the interviewer will first ask, whether to understand the block, whether the use of blocks, these questions equal to the opening, often is the beginning of a series of questions, so be sure to truthfully according to their own circumstances to answer. 1 What are the advantages of using block and using delegate to complete the delegation mode? The first thing to understand is the delegate mode, which is used extensively in iOS, which is an object adapter in the adapter pattern in design mode, and OBJECTIVE-C uses the ID type to point to everything, making the delegate mode more concise. Learn the details of the delegate model:iOS design mode----delegate ModeThe advantage of using block to implement the delegate mode is that the block code of the callback is defined inside the delegate object function, which makes the code more compact ;an Adaptation object no longer needs to implement a specific protocol, and the Code is more concise .   2 Multi-threading with blockGCD and Blockusing the Dispatch_async series method, the block can be executed in the specified mannerGCD Programming Example full definition of Dispatch_asyncvoid Dispatch_async (dispatch_queue_t Queue,dispatch_block_t block);function: Commits an asynchronously executed block in the specified queue, without blocking the current thread the thread that the block executes is controlled through the queue. The main thread executes the Finishblock object defined in the previous articleDispatch_async (Dispatch_get_main_queue (), ^ (void) {Finishblock ();});

iOS advanced face question----block section

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.