XCode: typeof class - compare two classes

To find out if an object belongs to a class, you can compare them exactly with this code:

if ([myCatObject class] == [MyCatClass class]){
    //do something with your cat
}

The same you can achieve with isMemberOfClass - method, wich returns a Boolean value that indicates whether the receiver is an instance of a given class

if ([myCatObject isMemberOfClass:[MyCatClass class]]){
    //do something with your cat
}

The static class - method returns the class object. If you like to find out wether your object is an instance of class or an instance of subclass the isKindOfClass - method is used.

if ([myCatObject isKindOfClass:[MyAnimalsObject class]]){
    //do something with your cat
}

Werbung



comments powered by Disqus

Copyright Dunkel & Iwer GbR | Datenschutzerklärung | Impressum