I have a class which contains a dictionary used for making web calls. Basically the key value pairs are used to create the data that will be posted to the URL if the web call requires any values. This object class is set up using JSON.
I have a method which takes this class object and uses it to set up the web call. My problem is, if no parameters are required, then the dictionary is set to null which is fine, this is what I want, but for some reason when I do an if statement to check if the dictionary is null, it is hitting the else statement indicating that it is not null. Method looks like this
-(void)webCall :(WebServiceCall *)webCall_p
{
//Creates a dictionary from the one stored in the WebResponse Class
NSMutableDictionary *dict = [[webCall_p getWebServiceResponse] getVariablesByRegexMap];
NSLog(@"%@", dict);
}
When I print it out I get this
<null>
Yet if I put in an if statement to check if it is null like so
if(dict == NULL)
{
NSLog(@"NULL");
}
else
{
NSLog(@"Not NULL");
}
It says not null. If I try to use the dict count command, like so
NSLog(@"%i", [dict count]);
The application crashes and brings up this error
-[NSNull count]: unrecognized selector sent to instance 0xaf8678 2012-11-23 11:48:44.005 Testing[3403:14003] *
Terminating app due to uncaught exception
‘NSInvalidArgumentException’, reason: ‘-[NSNull count]: unrecognized
selector sent to instance 0xaf8678’
I can’t for the life of me figure this out. Any help would be much appreciated
Aparently the value ist NSNull, which is an object, not nil. NSNull is a singleton
if (dict == NSNull)should work.