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.
NSObject
Other 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