iOS: Why can not I set nil to NSDictionary?
source link: https://www.codesd.com/item/ios-why-can-not-i-set-nil-to-nsdictionary.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
iOS: Why can not I set nil to NSDictionary?
This might be very basic question but I was wondering why can't I assign nil as NSDictionary value? I have following statement many places in my code. If [q objectForKey:@"text"]
is nil then App is crashing.
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:2];
[dict setObject:[q objectForKey:@"text"] forKey:@"text"];
I have to check everywhere for the nil before assigning it to dictionary. Is this the only correct way of doing? Am I missing something obvious?
if([q objectForKey:@"text"] != nil)
[dict setObject:[q objectForKey:@"text"] forKey:@"text"];
else
[dict setObject:@"" forKey:@"text"];
It wants an actual object... use NSNull
Related Articles
Why can not I set the image?
IOS: Why can not I program the frame for the button?
Why can not I set the properties of iteration variables in a foreach loop?
Why can not I set a breakpoint in my library?
Why can not I set onClickListener for a button in a dialog box view?
Why can not I set a view from a different ViewController view?
Why can not I set the value of an instance variable like this
Why can not I set a JavaScript function name property?
Why can not I set the asp: Label Text property by calling a method in the aspx file?
Why can not I set a title for my UINavigationController in Swift?
Why can not I set a background image in an ImageView declared in an xml fragment configuration from the associated fragments class?
Why can not I set the auto_increment value in my Magento configuration script?
Why can not I set ReadOnly on a smooth NHibernate References () mapping?
Why can not I set the value of a ProgressBar?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK