ios - Cannot Add PFRelation values to a specific objet -
i creating app user can create group, , add information within group. this, pfrobject
created in parse database , pfrelation
created object containing group info. having trouble adding relation info object want. instead of app adding info existing object, creates new object , relation, , adds info there. how can add data existing object? appreciate suggestions.
@ibaction func createnewgroupaction(sender: anyobject) { var groupinfo = pfobject(classname: "groupinfo") groupinfo["user"] = pfuser.currentuser()?.username groupinfo["interest"] = "cars" groupinfo.save() let relationinfo = pfobject(classname: "beatergroups") relationinfo["groupname"] = "carguys" let relation = relationinfo.relationforkey("groupinfo") relation.addobject(groupinfo) relationinfo.save() } var dataparse: nsmutablearray = nsmutablearray() func loaddata (){ var findgroups: pfquery = pfquery(classname: "beatergroups") findgroups.findobjectsinbackgroundwithblock { (objects: [anyobject]?, error: nserror?) -> void in if error == nil && objects != nil { if let objects = objects as? [pfobject] { object in objects { self.dataparse.addobject(object) } } } self.tableview.reloaddata() } } override func viewdidload() { super.viewdidload() loaddata() } override func numberofsectionsintableview(tableview: uitableview) -> int { return 1 } override func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int { return self.dataparse.count } override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { let cell: uitableviewcell = tableview.dequeuereusablecellwithidentifier(cellidentifier, forindexpath: indexpath) as! uitableviewcell let celldataparse: pfobject = self.dataparse.objectatindex(indexpath.row) as! pfobject cell.textlabel?.text = celldataparse.objectforkey("groupname")! as? string return cell } }
yes, behaviour expected using current code. let relationinfo = pfobject(classname: "beatergroups")
creating new object, add new row.
what need add relation existing beatergroups
object. can using query, e.g.
Comments
Post a Comment