OC Syntax--polymorphic dynamic recognition and @selector () pre-compilation directives specify selectors

Source: Internet
Author: User

Overriding: The subclass method overrides the parent class method, requiring the method name and parameters to be the same.

Overloading: Two or more than two method names in the same class, but with different parameters, the method body is also different.

Multi-State dynamic identification

is the object not a member of AClass or its subclasses? if ([Audi Iskindofclass:[car class]]) {NSlog (@ "Audi is a kind of Car");}
is the object not a AClass member? if ([Car Ismemberofclass:[car class]]) {NSlog (@ "Audi is member of Car");}
object is not a AClass subclassif ([Audi Issubclassofclass:[car class]]) {NSlog (@ "Audi is subclass of Car");}
determine whether two objects are of the same typeif ([Audi Class]==[benz class]) {NSlog (@ "Audi and Benz is the same class");}
whether the object responds Aselector the specified methodif ([Car respondstoselector: @selector (Run)]) {NSlog (@ "car responds to Run method");}
The @selector () precompiled directive specifies the selector, where the method name is in parentheses. the Aselector object invokes the specified method
SEL Action;[email protected] (run);[car performselector:action];equivalent to [car performselector: @selector (run)];
for the method specified like the call Aselector, pass the Parameter object-(ID) Performselector: (SEL) aselector;Withobject: (ID) object;
the Aselector object invokes the specified method, passing parameters Object1 and Object2-(ID) Performselector: (SEL) aselector;Withobject: (ID) object;Withobject: (ID) object;



OC Syntax--polymorphic dynamic recognition and @selector () pre-compilation directives specify selectors

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.