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.
The compare() method in Java compares two class specific objects (x, y) given as parameters. It returns the value: 0: if (x==y) -1: if (x < y)
This can occur through simple assignment, as shown in the following example. Value equality means that two objects contain the same value or values. For primitive value types such as int or bool, tests for value equality are straightforward.
Object comparison refers to the ability of an object to determine whether it is essentially the same as another object. You evaluate whether one object is equal to another by sending one of the objects an isEqual: message and passing in the other object.
Correct syntax is:
if ([bla class] == [NSString class])
You can also use -isMemberOfClass:
or -isKindOfClass:
messages from NSObject
protocol.
This should do it:
NSString *bla = [[NSString alloc] init];
if ( [bla isMemberOfClass: [NSString class]] == YES )
NSLog(@"Success");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With