Questions tagged [nsnull]

The NSNull class defines a singleton object used to represent null values in collection objects (which don’t allow nil values).

82 questions
177
votes
16 answers

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…
Biranchi
  • 16,120
  • 23
  • 124
  • 161
77
votes
6 answers

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…
shweta
  • 1,120
  • 1
  • 11
  • 25
71
votes
9 answers

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…
Navi
  • 1,696
  • 2
  • 17
  • 36
56
votes
5 answers

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)…
iosfreak
  • 5,228
  • 11
  • 59
  • 102
51
votes
6 answers

What's the difference between [NSNull null] 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?
Thanks
  • 40,109
  • 71
  • 208
  • 322
40
votes
6 answers

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…
Jeff
  • 4,751
  • 5
  • 31
  • 35
35
votes
5 answers

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: …
Lucien
  • 8,263
  • 4
  • 30
  • 30
17
votes
6 answers

Are NULL and nil equivalent?

Actually my question here is: are null and nil equivalent or not? I have an example but I am confused when they are equal when they are not. NSNull *nullValue = [NSNull null]; NSArray *arrayWithNull = [NSArray…
monish
  • 1,355
  • 5
  • 18
  • 32
16
votes
2 answers

How to make a if statement with NSNull in objective-c

I am develop a iPhone application, in which i need to use JSON to receive data from server. In the iPhone side, I convert the data into NSMutableDictionary. However, there is a date type data are null. I use the following sentence to read the…
Fan Wu
  • 237
  • 1
  • 4
  • 11
14
votes
4 answers

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…
jungziege
  • 245
  • 1
  • 4
  • 8
13
votes
8 answers

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…
Sebastien Peek
  • 2,528
  • 2
  • 23
  • 32
12
votes
4 answers

NSDictionaray dictionaryWithObjectsAndKeys adding NULL value

I want to create a NSDictionary with +[NSDictionary dictionaryWithObjectsAndKeys:]. One of my keys has a string but the string can sometimes be nil. If the string is nil, any other value key pairs I put afterward will be ignored because the list…
prostock
  • 9,327
  • 19
  • 70
  • 118
9
votes
3 answers

What is causing NSNull length unrecognized selector keyCommand error

I have this class/storyboard scene in a project that up to last night worked fine for the past 4 weeks i worked on it. I have managed to comment out practically everything and I still get the crash when tapping on the UITextField and typing a…
marciokoko
  • 4,988
  • 8
  • 51
  • 91
9
votes
6 answers

Is nil and (NSString *)[NSNull null] equivalent in checking empty NSString object

I have a NSString object, NSString *aString; then are the two following versions equivalent? Version 1 : if ( (NSString *)[NSNull null] == aString ) { // Logic handling } Version 2 : if ( nil == aString ) { // Logic handling } Reference…
George
  • 3,384
  • 5
  • 40
  • 64
9
votes
8 answers

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…
davidford.me
  • 824
  • 1
  • 15
  • 24
1
2 3 4 5 6