Objective-C - Comparing integers not working as expected?

You are comparing a pointer to an object, not an integer itself. You must first convert the object into an integer: if (userDictionary objectForKey:@"userid" integerValue == -1) { //Do stuff }.

I am receiving a JSON string from across the network. When decoded (using SBJSON libraries), it becomes an NSDictionary that SHOULD contain a number of some sort for the key 'userid'. I say 'should' because when I compare the value to an int, or an NSINTEGER, or NSNumber, it never evaluates correctly.

The value inside the dictionary I am testing with is -1. When I print it out to console using NSLog it even shows it is -1. Yet when I compare it to -1 in the 'if' statement, it evaluates to false when it should be true.

I've even tried comparing to NSNumber numberWithInt: -1, and it still evaluates to false. What am I doing wrong? Thanks in advance for your help!

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions