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
Erro because you are comparing NSNumber
with int
.
Try like -
if ([success isEqual:[NSNumber numberWithInt:1]])
or
if ([success intValue] == 1)
You should use [success intValue] == 1
. An NSNumber is a class, so number is a pointer, not the direct value.
NSNumber
is an object (ie 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) {
...
}
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!
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.