OBJECTIVE-C study notes-Next day (1)

Source: Internet
Author: User

In Objective-c, the invocation method takes a message-passing mechanism.

Reference article: http://blog.csdn.net/xingyevc/article/details/39397873

If a message is passed to an object, the dynamic binding mechanism of OC is used to determine the method that needs to be called.

At the bottom, all methods are ordinary C-language functions.

However, when the object receives the message, which method to drop is completely in the run-time decision, and can even change when the program is running.

These features make OC known as a true dynamic language.

To send a message to an object:

ID returnvalue = [Someobject messagename:parameter];

Translate to:

ID returnvalue = objc_msgsend (Someobject, @selector (messagename), parameter);  

The Objc_msgsend function invokes the appropriate method based on the receiver and the type of the selector.

In order to do this, the method needs to search its "method list" (List of methods) in the class to which the recipient belongs

If you can find a method that matches the selection sub-name, jump to its implementation code.

If not, then follow the inheritance system to continue to look up, and so find the name matching method before jumping.

If the matching method is not found at the end, then "message forwarding" is performed

OBJECTIVE-C study notes-Next day (1)

Related Article

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.