Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
nabih safadi
1,807 PointsiOS swift parse multiple objects update
i have 2 objects(parent , child) with cash and value fields for each object . at pressing a button , it does some calculations and update objects fields to the new values ,I'm able to update the parent fields to the new values but the child values remain as they are.
heres the code :
// calculations
var parentNewCash = cash! - childValue
var parentNewValue = value! + childValue
var childNewCash = childCash + (10 * childValue / 100)
//update parent fields
var queryParent = PFQuery(className:"_User")
//get parent ID
var currentUserId = PFUser.currentUser()?.objectId!
queryParent.getObjectInBackgroundWithId(currentUserId!) {
(parent: PFObject?, error: NSError?) -> Void in
if error != nil {
println(error)
} else if let parent = parent {
parent["cash"] = parentNewCash
parent["value"] = parentNewValue
parent.saveInBackground()
}
}//end parent query
I'm trying to update child fields like this but its not updating
var queryChild = PFQuery(className:"_User")
queryChild.getObjectInBackgroundWithId(objectIds[(counter - 1) ]) {
(child: PFObject?, error: NSError?) -> Void in
if error != nil {
println(error)
} else if let child = child {
child["cash"] = childNewCash
child.saveInBackground()
}
}//end child query
where objectIds[(counter - 1) ] is the selected user which is the child. if i have to use save all method , please provide me with an example