0

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];

2 Answers 2

1

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];
Sign up to request clarification or add additional context in comments.

Comments

1

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.