I'm having a regular issue with my project, using Parse Server. First, I call a Parse Cloud function to populate a user's data list :
var dataSet: Set<MyData>?
func loadData(withParameters parameters: [String : Any]) {
PFCloud.callFunction(inBackground: "loadData", withParameters: parameters) { (success, error) in
if let objects = success as? [[String : Any]] {
let dataTable: [MyData] = objects.map({ (object) -> MyData in
let myData = MyData(dataSource: PFObject(className: "MyData",
dictionary: object))
myData.dataSource?.objectId = object["objectId"] as? String
return myData
})
if self.dataSet == nil {
self.dataSet = []
}
self.dataSet = Set(dataTable)
}
}
}
On the code mentioned above, I have to set the objectId
because without this, no matter how many objects I fetch from Parse, when I reduce the array to a set with the last instruction I end up with only one object in it.
However, although this works, when I call this function again to update user's data, I get this error on the myData.dataSource?.objectId = temp["objectId"] as? String
line :
Attempted to change an objectId to one that's already known to the Offline Store.
Tried to find some information about it but nothing very relevant...
Thanks for your help.