how do we compare 2 class names of an object

18,806

Solution 1

Correct syntax is:

if ([bla class] == [NSString class])

You can also use -isMemberOfClass: or -isKindOfClass: messages from NSObject protocol.

Solution 2

This should do it:

NSString *bla = [[NSString alloc] init];
if ( [bla isMemberOfClass: [NSString class]] == YES )
     NSLog(@"Success");
Share:
18,806
Frank
Author by

Frank

Cross platform Mobile developer

Updated on June 04, 2022

Comments

  • Frank
    Frank almost 2 years

    Is there a way to get compare class name betweeen 2 objects?

    Like:

    NSString *bla = [[NSString alloc] init];
    if([bla class] isEqual: NSString])
     NSLog(@"success");
    

    unsure if my syntax is correct.