我正在进行查询,我正在检查“父”列中的值是否为字符串newLogObjectId。我显然不能这样做,因为指针和字符串是不同的值类型,(返回nil)。当我查看Parse中的数据时,我注意到在Parent列中,列出了objectId,但是在一个按钮中,单击该按钮时会加载NewLog类。
如何在代码“query1.whereKey(”Parent“,equalTo:newLogObjectId)中将”Parent“更改为指针中的objectId?像“Parent.objectId”这样的东西
//ObjectId of row of Marker Selected, a string, for example, "MCeKMyxRIt"
let newLogObjectId = objectIdArray[markerIndex]
//Query ComparablePhotos class
let query1 = PFQuery(className: "ComparablePhotos")
//Grab all rows of Parent, equal to newLogObjectId ex: "MCeKMyxRIt"
//Issue: "Parent" is a pointer, not a String. Parent has an objectId
query1.whereKey("Parent", equalTo:newLogObjectId)
//Get result as an object
viewRecordObject = query1.findObjects() as! [PFObject]
答案 0 :(得分:1)
根据我的经验,当谈到图像图片或大数据时,最好使用findObjectsInBackgroundWithBlock方法
var query = PFQuery(className:"")
findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in {
if error == nil{
// do whatever you want
if let data = objects as![PFObject]{
// now you could just append your array with data
// something like self.arrayofObjects.append(data)
}
}
}
方法,因为它可以让您检查错误,并且更容易将这些对象添加到您的数组中。
答案 1 :(得分:0)
如果您只有一个objectId,请创建一个新的ParseObject,将其objectId设置为newLogObjectId,然后在查询中使用该新创建的对象(指针)。
var myNewLog = PFObject(className: "NewLog")
myPointer.objectId = newLogObjectId
query1.whereKey("Parent", myNewLog)