OBJECT-C syntax-nsobject common methods and reflections

Source: Internet
Author: User

NSObject Common methods

    • -(BOOL) Iskindofclass: (Class) AClass//To determine whether an instance of AClass or AClass subclass, AClass can be obtained by [class name class]
    • -(BOOL) Ismemberofclass: (Class) AClass//Determine if the instance is AClass (excluding AClass subclasses)
    • -(BOOL) Conformstoprotocol: (Protocol) Aprotocol//Determine if the object implements the Aprotocol protocol
    • + (BOOL) Instancesrespondtoselector: (SEL) aselector//Determine if the object of this class has a method provided by the parameter Aselector
    • -(BOOL) Respondstoselector: (SEL) aselector//Determine if the object has the method provided by the parameter Aselector
    • -(void) Performselector: (SEL) Aselector withobject: (ID) anargument afterdelay: (nstimeinterval) delay//Delay call parameter provided method, Method required parameters are passed in Withobject

Reflection

    • Reflection of Class

Instantiating an object as a string of a class name

Class class = Nsclassfromstring (@ "Student");

Student *stu = [[Class alloc] init];

Turn the class name into a string

Class class = [Student class];

NSString *classname = Nsstringfromclass (Class);

    • The reflection of the SEL

Instantiating methods by string form of a method

SEL selector = nsselectorfromstring (@ "setName:");

[Stu Performselector:selector withobject:@ "Mike"];

Turn a method into a string

Nsstringfromselector (@selector (setName:));

OBJECT-C syntax-nsobject common methods and reflections

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.