Use Iskindofclas to discover whether an object is an instance of a class or its subclasses

Source: Internet
Author: User

Discovers whether an object is an instance of a particular class or its subclasses

To discover whether an object is an instance of a class or its subclasses, call the method on the object isKindOfClass: . When an application needs to discover its response to a message (either implemented or inherited), it sometimes makes the above checks.

static int sum = 0;
For (ID item in MyArray) {
    if ([Item Iskindofclass:[nsnumber class]]) {
        int i = (int) [item intvalue];
        sum + = i;
    }
}

isKindOfClass:method to treat an Class object of the type as a parameter, and to get this object, call the method on the class symbol class . The Boolean value returned by this method is then evaluated and the corresponding operation continues.

NSObjectOther methods are declared to discover information about object inheritance. For example, the isMemberOfClass: method tells you whether an object is an instance of a particular class, and isKindOfClass: tells you whether the object is a member of that class or any of its descendant classes.

Use Iskindofclas to discover whether an object is an instance of a class or its subclasses

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.