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:
现在,在执行了三次requestButtonPressed函数后,在解析中发生:
However. I don't want that to happen when I execute the function requestButtonPressed
three times. I want it to be something like this:
然而。我不希望在执行requestButtonPressed三次时发生这种情况。我希望它是这样的:
Anybody have a solution to this problem?
有人能解决这个问题吗?
2 个解决方案
#1
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.
每次使用此语句var prayerRequests = PFObject(className:“prayerRequests”)时,都会创建一个新的PFObject。为了更新对象,您需要首先查询对象,然后更新其字段。在这种情况下,您应该首先通过查询对象来获取数组,然后修改/添加数据到数组中,然后更新对象。
#2
0
Instead of doing addObject, do insertObject:{yourObject} atIndexPath:{storingPosition} forKey:{@"youKey"}.
而不是做addObject:{yourObject} atIndexPath:{storingPosition} forKey:{@"youKey"}。
And the the value you are adding is an array ["YOIDJFO"]
, object should be like {"YOIDJFO"}
你添加的值是一个数组["YOIDJFO"]对象应该是{"YOIDJFO"}
#1
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.
每次使用此语句var prayerRequests = PFObject(className:“prayerRequests”)时,都会创建一个新的PFObject。为了更新对象,您需要首先查询对象,然后更新其字段。在这种情况下,您应该首先通过查询对象来获取数组,然后修改/添加数据到数组中,然后更新对象。
#2
0
Instead of doing addObject, do insertObject:{yourObject} atIndexPath:{storingPosition} forKey:{@"youKey"}.
而不是做addObject:{yourObject} atIndexPath:{storingPosition} forKey:{@"youKey"}。
And the the value you are adding is an array ["YOIDJFO"]
, object should be like {"YOIDJFO"}
你添加的值是一个数组["YOIDJFO"]对象应该是{"YOIDJFO"}