2

I just learned how to store an array into a Parse Cloud using the example provided by the Parse Documentation:

gameScore.addUniqueObjectsFromArray(["flying", "kungfu"], forKey:"skills")
gameScore.saveInBackground()

Now, utilizing this logic, I want to append strings into the array. So this is what I wrote:

@IBAction func requestButtonPressed(sender: AnyObject) {
    var prayerRequests = PFObject(className: "PrayerRequests")
    prayerRequests.addObject(["YOIDJFO"], forKey:"skills")
    prayerRequests.saveInBackground()
}

Now, after having executed the function requestButtonPressed three times, in parse this is happening:

Parse Array

However. I don't want that to happen when I execute the function requestButtonPressed three times. I want it to be something like this:

enter image description here

Anybody have a solution to this problem?

2 Answers 2

2

Every time you use this statement var prayerRequests = PFObject(className: "PrayerRequests") a new PFObject will be created. In order to update a object you need to query the object first and then update its field. In your case you should first get the array by querying for the object, modify / append data to the array and then update the object.

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

1 Comment

That was one solution that I was thinking of but then wouldn't that mean I would have to create a new object every time I want to modify the array? That would mean I would have many unnecessary objects? Maybe?
0

Instead of doing addObject, do insertObject:{yourObject} atIndexPath:{storingPosition} forKey:{@"youKey"}.

And the the value you are adding is an array ["YOIDJFO"] , object should be like {"YOIDJFO"}

1 Comment

Thank you so much for the response. Could you please translate the syntax into swift code? I tried it and I'm getting some syntax errors...

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.