I have this statement:
[custData setObject: [rs stringForColumnIndex:2] forKey: @"email"];
where [rs stringForColumnIndex:2] obtained from a SQLite3 d/b has a value of nil. The app crashes giving me the error:
NSCFDictionary setObject:forKey:]: attempt to insert nil value (key: email)'
Is there a way to prevent this? (like a setting for NSMutableDictionary?)
UPDATE: this is what I finally did:
[custData setObject: ([rs stringForColumnIndex:2] != nil? [rs stringForColumnIndex:2]:@"") forKey: @"email"];
There is a non-
nilobject calledNSNullthat is built specifically to representnils in situations where “plain”nilis not acceptable. If you replace yournils with[NSNull null]object,NSDictionarywill take them. You would need to check forNSNullon the way out, though.Note that this is important only when you must differentiate between a value not being set and a value being set to
nil. If your code is such that it can interpret a missing value asnil, you do not need to useNSNullat all.