Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i check NSNumber is null?

 NSDictionary *regionDict = (NSDictionary *) region;
            NSNumber *lat = [regionDict objectForKey:@"lat"];
            //[latitude addObject:lat];
            NSNumber *lng = [regionDict objectForKey:@"lng"];
            //[longitude addObject:lng];
            NSLog(@"%@%@%@",lat,lng,titles);

            if(lat == [NSNumber numberWithFloat:0.00]  && lng == [NSNumber numberWithFloat:0.00])
            {
                NSLog(@"%@%@%@",lat,lng,titles);
            }
            else
            {
                CLLocationCoordinate2D coord;
                coord.latitude =lat.doubleValue;
                coord.longitude =lng.doubleValue;
                MapViewAnnotation *annotation =[[MapViewAnnotation alloc]initWithTitle:titles AndCoordinate:coord];
                [self.mapView addAnnotation:annotation];
            }

if condition is not satisfied because of NSNumber not check with null value. what is the way i can check? Tell me possible ways.. for checking null.

like image 764
Priyank Gandhi Avatar asked Mar 24 '14 13:03

Priyank Gandhi


2 Answers

You can check if an object is null by doing

if ([myObject isKindOfClass:[NSNull class]])

But if you want to check if a float boxed in a NSNumber is zero, you can do

if (lng.floatValue == 0. && lat.floatValue == 0)
like image 154
Cyrille Avatar answered Oct 22 '22 15:10

Cyrille


I've been checking if NSDecimalNumber was null using:

if (decimalNumber == nil)

This is working great for me.

like image 2
staticnz Avatar answered Oct 22 '22 14:10

staticnz