checking for null when reading from APIs

the best way to check for NSNull when reading from a API : [ this is just an example you can modify it however you want ]

for (NSDictionary *tmpdata in dataarray) {
@try {
tmplink = [tmpdata objectForKey:@"link"];
tmplat = [tmpdata
valueForKeyPath:@"location.latitude"];
if (tmplat != (id)[NSNull null] ) {
NSLog(@"lat %@",tmplat);
}
tmplong = [tmpdata
valueForKeyPath:@"location.latitude"];
if (tmplong != (id)[NSNull null] ) {
NSLog(@"long %@",tmplong);
}
if (tmplong != (id)[NSNull null] && tmplat != (id)[NSNull null]) {
sflyPicInformation *sflypic = [[sflyPicInformation alloc] init:tmplat:tmplong:tmplink];
[perdatavalues addObject:sflypic];
}
}
@catch (NSException *exception) {
NSLog(@"ignore");
}

Leave a Reply

Your email address will not be published. Required fields are marked *