Reputation: 787
Okay I have a classNamed: "PrivateGroups". Each row in PrivateGroups contains "GroupName" and "Password". In a UIView, if the user enters the GroupName and Password and hits submit, I want to add their user objectId to that specific groupname/password entry under "members".
This is the code I have that isn't working:
var query = PFQuery(className: "PrivateGroups")
query.whereKey("privatename", equalTo: joinname.text)
query.whereKey("password", equalTo: joinpassword.text)
query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if objects.count == 1 {
for object in objects {
query.getFirstObject().addUniqueObject(PFUser.currentUser().objectId, forKey: "members")
query.getFirstObject().saveInBackground() }}
so if you match the "members" and "password" and press the button, i want to add the user's object id to "members"
Upvotes: 0
Views: 77
Reputation: 921
In your loop for object in objects
you shouldn't need to also call query.getFirstObject()
since you already have the object. Instead, try
for object in objects {
if let arr = object["members"]{
if(arr.containsObject(PFUser.currentUser().objectID == false){
arr.addObject(PFUser.currentUser().objectID)
object.saveInBackground()
}
}
}
Upvotes: 1