Tag: 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 […]

Replace occurrences of NSNull in nested NSDictionary

This question is similar to this question, however this method only works on the root level of the dictionary. I’m looking to replace any occurrence of NSNull values with an empty string, so that I can save the full dictionary to a plist file (if i add it with the NSNull’s the file won’t write). […]

Detect a Null value in NSDictionary

I have an NSDictionary that’s populated from a JSON response from an API server. Sometimes the values for a key in this dictionary are Null I am trying to take the given value and drop it into the detail text of a table cell for display. The problem is that when I try to coerce […]