When i call this if condition, The condition inside the if does not get executed.
Code used to call an element
if([NSNumber numberWithFloat:(([[[shared instance].y objectAtIndex:0] floatValue]))>10])
{
[MONObject sharedInstance1[.counterPlus++; //counter used to update the value
}
Counter value gets updated irrespective of the condition inside if? Is this the way to get a element from the array and compare?
Note: i have created a single tone array!
Please help me!
Don’t try and cram everything into one statement – this is terrible coding style, hard to debug (as you’ve found) and awful to maintain. Use some intermediate variables so you can see what’s going on.
The reason the condition is always true, is that your if statement boils down to:
-[NSNumber numberWithFloat:]is always true – in fact any object always equates to true. So even[NSNumber numberWithBool: NO]is true.If you just want to check whether your value is greater than 10 (assuming your array contains
NSNumbers), you need: