我已经成功地建立了关系。现在我不知道如何查询它我可以在网站上看到数据我可以看到它相互链接
这是我如何制作“链接”PFRelation
var query = PFQuery(className:"Profile")
let objectID = data.valueForKey("objectId") as String?
query.getObjectInBackgroundWithId(objectID) {
(rodObj1: PFObject!, error: NSError!) -> Void in
if error == nil {
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MMM-d-yyyy HH:mm:ss zzz"
let str1 = dateFormatter.stringFromDate(NSDate())
var dateFromString1 = dateFormatter.dateFromString(str1)
var profil = PFObject(className: "SwitchColor")
profil["Rod"] = dateFromString1
println("Profil = ********\(profil)")
profil.saveEventually()
let rod: PFRelation = rodObj1.relationForKey("SwitchColor")
rod.addObject(profil)
println("rodObj = *********\(rod)")
rodObj1.saveEventually()
}
}
这是我如何进行查询“这不起作用”
let rodobj: PFObject = PFObject(className: "Profile")
let relationRod: PFRelation = rodobj.relationForKey("SwitchColor")
let query: PFQuery = relationRod.query()
query.orderByDescending("createdAt")
query.findObjectsInBackgroundWithBlock{(objQ: [AnyObject]!, error: NSError!) -> Void in
if let staffObjects = objQ as? [PFObject] {
for staff in staffObjects {
self.countObj.addObject(staff)
staff.pin()
self.barChart.reloadData()
dispatch_async(dispatch_get_main_queue(), {
self.tableView.reloadData()
self.refreshControl.endRefreshing()
})
println("countObj: \(self.countObj.count)")
}
}
}