NSDictionary objectAtKey returns (null)? July 31, 2009
Posted by Ameya in iPhone.Tags: iPhone, NSDictionary NSNull, NSDictionary null, NSNull, Tutorial
trackback
A small work around for problem faced with NSDictionary null return problem.
In cases like
NSString *myImageURL = [user objectForKey:@"imageURL"];
where [user objectForKey:@"imageURL"] may return NSNull object.
This makes myImageURL a NSNull object hence cannot be compared using conventional comparisons. An NSNull is an invalid memory allocation or an error.:)
Two alternative solutions are
if ((NSNull *)[user objectForKey:@"imageURL"] == [NSNull null]) { }
and to convert to string if the above does not works.
NSString *myImageURL = [NSString stringWithFormat:@"%@",[user objectForKey:@"imageURL"]];
this can be compared by
if([imgURL isEqualToString:@""]){
}
Advertisement
Comments»
No comments yet — be the first.