14

iOS: Why can not I set nil to NSDictionary?

 2 years ago
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.
neoserver,ios ssh client

iOS: Why can not I set nil to NSDictionary?

advertisements

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?

Why can not I set image? class ViewController:UIViewController,UITableViewDelegate,UITalbeViewDataSource{ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withId

IOS: Why can not I program the frame for the button?

Here is a strange thing, but I couldn't figure it out. I can not programmatically set frame for the button. I have a button with IBOutlet as beyondViewButton and I control-dragged it from view to the ViewController.m file @interface and @end section,

Why can not I set the properties of iteration variables in a foreach loop?

string newName = "new name"; int[] numbers = new int[] { 1, 2, 3 }; var people = numbers.Select(n => new Person() { Name = n.ToString() }); foreach (var person in people) { person.Name = newName; } Debug.WriteLine(people.First().Name == newNa

Why can not I set a breakpoint in my library?

the goal is to debug a method deep within a library. We can debug c functions in that same library (as long as they are not in the .m files), but apparently no Objective-C code, or even c code within any .m file. When I try to set breakpoints manuall

Why can not I set onClickListener for a button in a dialog box view?

I have a custom dialog which described below. My Custom Dialog layout (*my_dialog.xml*) which only contain a "dismiss" button: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas

Why can not I set a view from a different ViewController view?

@IBOutlet weak var containerView: UIView! override func viewDidLoad() { super.viewDidLoad() let storyboard = UIStoryboard(name: "LinkDetail", bundle: nil) var vc : UIViewController = storyboard.instantiateViewControllerWithIdentifier("red&q

Why can not I set the value of an instance variable like this

I'm trying to understand how to use setter methods in Ruby but I don't understand why this code does not work. Is it not working because I already set he price of book when I created the book object? If I change the line in question to book.price = b

Why can not I set a JavaScript function name property?

I am learning JavaScript and read that functions are like objects and can have properties set like this: var person = function(){ } person.name="John Smith"; //output "" person.age=21; //output 21 person.profession="Web Developer&

Why can not I set the asp: Label Text property by calling a method in the aspx file?

Can somebody please explain this to me: I have a label and I want to be able to set the Text property by calling a method in the aspx file. It works fine if I set the property in code behind, but I really want to set this property in the aspx file. I

Why can not I set a title for my UINavigationController in Swift?

I have a UINavigationController in my app and I added there the segmented control: I also have a button and when user presses it, I want to hide the segmented control and display a string instead. I can hide the segmented control by doing: segmentedC

Why can not I set a background image in an ImageView declared in an xml fragment configuration from the associated fragments class?

I am absolutly new in Android development and I have some problem developing my first app. So I have the following situation: 1) I have this fragment_screen_slide_page.xml file that contains the element of a fragment that is shown into a view and hav

Why can not I set the auto_increment value in my Magento configuration script?

I am creating a custom module with a few custom database tables. I need to set the auto_increment value to 5000 rather than having the default of 1. This can be accomplished pretty easily, but I am running into problems when trying to do it via a Mag

Why can not I set ReadOnly on a smooth NHibernate References () mapping?

In Fluent NHibernate, References() returns an object which doesn't support the 'ReadOnly()' method. I'm trying to create this sort of mapping (i.e. one where an update is not propagated to the referred item): <many-to-one update="false" inser

Why can not I set the value of a ProgressBar?

friends,thank you for your time! There's a problem in the codes below in WPF.I use a ProgressBar and a Animation which show the progress of value changes.When the Animation finished,I try to reset the value to 0 ,so that the ProgressBar can begin a n

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK