Reputation: 5132
I am trying to use Parse to save data for my iPhone app. When I save static things, it works fine. However, when I try to set the value of a variable and then save it, I get an error saying, “Implicit conversion of ‘int’ to ‘id’ is disallowed with ARC.”
How do I fix this so I can save the value of maxScore to my Parse backend?
int maxScore = 500;
//Save round data to parse
PFObject *roundScore = [PFObject objectWithClassName:@"UserCoor"];
roundScore[@"UserLat"] = maxScore;
[roundScore saveInBackground];
Upvotes: 0
Views: 581
Reputation: 5417
The issue is that you can't can't pass a primitive type such as int
to roundScore[@"UserLat"] = maxScore
. This keyed subscript notation is just a call to setObject:(id)obj forKeyedSubscript:(id<NSCopying>)key
, which as you can see takes a object of type id
as the obj parameter.
You can box your int value into an NSNumber
(not a primitive type) easily by using the literal @()
. Like so:
roundScore[@"UserLat"] = @(maxScore);
Upvotes: 1
Reputation: 14169
As the error says, it expects a a pointer to an Objective-C object, and instead of an object, you're passing in a primitive type (int). You may want to use
NSNumber *maxScore = [NSNumber numberWithInt:500];
Upvotes: 1