0

I want to create (or update) a PFObject with an array of strings, so that each element of the array can be editable. For example, I want the array to contain the words "Hello" and "World" so that if I wanted, I could access and rewrite the first element of the array to instead say "Goodbye".

Here's what I have:

PFObject *newStringArray = [PFObject objectWithClassName:@"myFirstClass"];
[newStringArray setObject:@"Hello" forKey:@"arrayOfStrings"];
[newStringArray saveInBackground];

The above code doesn't give me any errors, and it doesn't save to Parse. I've also tried using:

[newStringArray addObjectsFromArray:@[@"Hello", @"World"] forKey:@"arrayOfStrings"];

But this code returns the error "Error: invalid type for key arrayOfStrings, expected string, but got array"

Please let me know if you have any suggestions for how I can fix the array problem, or if I should be trying a different method of collecting/accessing strings within a wall of text. Thanks

1 Answer 1

1

It will only save in Parse if the column arrayOfStrings in your class myFirstClass actually expects an array. In that case the code would look something like this:

[newStringArray setObject:@[@"Hello", @"World"] forKey:@"arrayOfStrings"];

But your class myFirstClass obviously expects a string as the error message is telling you. So you will have change that in Parse itself.

Also always check the correct spelling for the classes and keys. They are case sensitive.

By the way, addObjectsFromArray: only does what it says. It will add the objects from that array to the one already set for that key. If there is no array set it will not work.

Sign up to request clarification or add additional context in comments.

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.