If we have an API that requires only 2 out of an objects 5 properties and iPhone app doesn\'t require them to instantiate an object, when the object is used in the params NSDici
You cannot insert nil
into collections (dictionaries, arrays, index sets, etc).
You can, however, insert [NSNull null]
into them as this is what they made it for
Inserting objects into the dictionary becomes quite easy (if the property is nil
, insert an NSNull
instead). Then, when pulling things out of the dictionary, a quick if(myReturnedObject == [NSNull null])
will tell you if the returned value is valid, as NSNull
is a singleton and thus every NSNull
is in fact the same object.
Edit: Paul.s has an excellent example of insertion behavior for your case, complete with ternary operator usage.
Edit Again: Despite the below comment, it is factually confirmed in the Apple docs linked above that NSNull does not crash when added to collections.