user1540999
user1540999

Reputation: 86

Compare NSdata carrying dictionary object to a String

I want to figure out how to do this

NSData *xxx = [xxx objectForKey:@"xxx"];
if (xxx == @"xxx")
//do somthing

Upvotes: 0

Views: 168

Answers (2)

Nicolas Bachschmidt
Nicolas Bachschmidt

Reputation: 6505

Or you may just use isEqual: which allows to compare to any object, without having to test for the class first.

id obj = [dict objectForKey:@"key"];
if ( [obj isEqual:@"text"] ) {
    //...
}

Upvotes: 1

TeaPow
TeaPow

Reputation: 677

You can use introspection to determine whether or not an object is the same data type as another, but you'll have to do it like this (note the type id);

id *obj = [dict objectForKey:@"key"];

if ([obj isKindOfClass:[NSString class]])
{
    if ([obj isEqualToString:@"text"])
    {
       //...
    }
}

Upvotes: 1

Related Questions