Reputation: 123
on following code i'm get the errormessage: Implicit conversion of 'int' to 'NSNumber *' is disallowed with ARC.
What i'm making wrong?
<pre>
<code>
NSDictionary *results = [jsonstring JSONValue];
NSNumber *success = [results objectForKey:@"success"]; // possible values for "success": 0 or 1
if (success == 1) { // ERROR implicit conversion of int to NSNumber disallowed with ARC
}
</code>
</pre>
Thanks for any help or hint!
regards, Daniel
Upvotes: 12
Views: 31432
Reputation: 11839
Erro because you are comparing NSNumber
with int
.
Try like -
if ([success isEqual:[NSNumber numberWithInt:1]])
or
if ([success intValue] == 1)
Upvotes: 28
Reputation: 14169
If success
should indicate a boolean, you may want to try this
NSDictionary *results = [jsonstring JSONValue];
NSNumber *success = [results objectForKey:@"success"];
if ([success boolValue]) {
// success!
}
Upvotes: 1
Reputation: 53551
NSNumber
is an object (i.e. a pointer), so you can't just compare it to a integer literal like 1
. Instead you have to extract the int
value from the number object:
if ([success intValue] == 1) {
...
}
Upvotes: 3
Reputation:
You should use [success intValue] == 1
. An NSNumber is a class, so number is a pointer, not the direct value.
Upvotes: 15