I habe written a function, that updates data in parse
func updateParse(className: String, whereKey: String, equalTo: String, updateData: Dictionary<String, Any>) {
let query = PFQuery(className: className)
query.findObjectsInBackgroundWithBlock {
(objects, error) -> Void in
if error == nil {
if let objects = objects as? [PFObject] {
for object in objects {
query.getObjectInBackgroundWithId(object.objectId!){
(prefObj, error) -> Void in
if error != nil {
print(error)
} else if let prefObj = prefObj {
for (key, value) in updateData {
prefObj[key] = value // Cannot assign a value of type 'Any' to a value of type 'AnyObject?'
}
prefObj.saveInBackground()
}
}
}
}
} else {
print("Error: \(error!)")
}
}
}
i call it with
let imageData = UIImagePNGRepresentation(self.uploadPreviewImage.image!)
let parseImageFile = PFFile(name: "userProfileImage.png", data: imageData!)
updateParse("ProfileImages", whereKey: "uploader", equalTo: "Phil", updateData: ["imageFile":parseImageFile])
I have commented the error in the corresponding line. It is important to note that the type is not always a picture. Sometimes a string.