If you look here:
You will see that I made a PFUser and added two new objects to it, a sentItems
array and a receivedItems
array. In my code I wanted to access those and append and change them, so I asked for help and got this:
var receivedItemsArr = PFUser.currentUser()!["receivedItems"] as? [Item]
var sentItemsArr = PFUser.currentUser()!["sentItems"] as? [Item]
Item
is just an object that I made that I want the array to hold. This doesn't work; it won't save, nor will it get for me what's in the array.
What Swift code do I need to write that would help me in the fact that it would make two new variables that would be the contents of those arrays from Parse, and that I would be able to save them back?
Lets say you have create a new class named "Data".
var dummy = ["1","2"]
var dummy2 = ["3","4"]
var ObjectsToSave = PFObject(className: "Data")
var username = PFUser.currentUser()?.username
ObjectsToSave["receivedItems"] = dummy
ObjectsToSave["sentItems"] = dummy2
ObjectsToSave["username"] = username
ObjectsToSave.saveEventually { (success:Bool, error:NSError?) -> Void in
if error == nil {
// there is no error so object was save
}
else{
// error
}
}
I think you are looking for something like that