Tag: nsnull

Testing equality to NSNull

Below is a code block, that is supposed to test to see if a dictionary is null, and if it isn’t, pull out the correct object. However, for some reason, despite the fact that the if check fails, the code still executes. Is there some quirk with how NSNull works that I don’t understand, or […]

NSNull handling for NSManagedObject properties values

I’m setting values for properties of my NSManagedObject, these values are coming from a NSDictionary properly serialized from a JSON file. My problem is, that, when some value is [NSNull null], I can’t assign directly to the property: fight.winnerID = [dict objectForKey:@”winner”]; this throws a NSInvalidArgumentException “winnerID”; desired type = NSString; given type = NSNull; […]

: unrecognized selector sent to instance 0x43fe068

I am not exactly sure where this is coming from. I have a breakpoint on exceptions set but it does not show me what is really happening: libobjc.A.dylib`objc_exception_throw: 0x40308b9: pushl %ebp 0x40308ba: movl %esp, %ebp 0x40308bc: pushl %ebx 0x40308bd: pushl %edi 0x40308be: pushl %esi 0x40308bf: subl $0x7ec, %esp 0x40308c5: calll 0x40308ca ; objc_exception_throw + 17 […]

Removing nulls from a JSON structure recursively

I’m frequently finding the need to cache data structures created by NSJSONSerialization to disk and as -writeToFile fails if there are nulls, I need a fix that works when the structure is unknown. This works, and direct mutation is allowed as the instances of NSMutableDictionary themselves are not being enumerated, but it feels a bit […]

What's the difference between and nil?

Here’s a context where I have seen that: NSMutableArray *controllers = [[NSMutableArray alloc] init]; for (unsigned i = 0; i < kNumberOfPages; i++) { [controllers addObject:[NSNull null]]; } why not nil in that place?

Replace all NSNull objects in an NSDictionary

I’m curious, I currently have an NSDictionary where some values are set to an NSNull object thanks to the help of json-framework. The aim is to strip all NSNull values and replace it with an empty string. I’m sure someone has done this somewhere? No doubt it is probably a four liner and is simple, […]

How to detect if NSString is null?

I have a piece of code that detects if a NSString is NULL, nil, etc. However, it crashes. Here is my code: NSArray *resultstwo = [database executeQuery:@”SELECT * FROM processes WHERE ready=’yes’ LIMIT 0,1″]; for (NSDictionary *rowtwo in resultstwo) { NSString *getCaption = [rowtwo valueForKey:@”caption”]; if (getCaption == NULL) { theCaption = @”Photo uploaded…”; } […]

Difference between nil, NIL and, null in Objective-C

I want to know the difference between nil, NIL and null. I’ve googled around and found this: nil -> null pointer to Objective-C object NIL -> null pointer to Objective-C class null -> null pointer to primitive type or absence of data But I’m not able to understand the terms “Objective-C object” and “class” clearly. […]

When should I use nil and NULL in Objective-C?

This is sample code: NSDictionary *myDictionary = [NSDictionary dictionary]; NSNumber *myNumber = [myDictionary valueForKey: @”MyNumber”]; NSLog(@”myNumber = %@”, myNumber); // output myNumber = (null) if (myNumber == nil) NSLog(@”test 1 myNumber == nil”); if (myNumber == NULL) NSLog(@”test 2 myNumber == NULL”); if ([myNumber isEqual:[NSNull null]]) NSLog(@”test 3 myNumber == [NSNull null]”); When should I […]

How can I check if an object in an NSArray is NSNull?

I am getting an array with null value. Please check the structure of my array below: ( “< null>” ) When I’m trying to access index 0 its crashing because of -[NSNull isEqualToString:]: unrecognized selector sent to instance 0x389cea70 Currently its crashing because of that array with a crash log: *** Terminating app due to […]