Parse(ios)

时间:2015-07-19 22:06:59

标签: ios swift parse-platform

我正在进行查询,我正在检查列#34; Parent"中的值是否为字符串newLogObjectId。我显然不能这样做,因为指针和字符串是不同的值类型,(返回nil)。如何将字符串与指针中的字符串进行比较?

    //A string, for example, "MCeKMyxRIt"
    let newLogObjectId = objectIdArray[markerIndex]

    let query1 = PFQuery(className: "ComparablePhotos")
    //"Parent" is a pointer referencing an objectId in another class.  "newLogObjectId" is a string  How do I check to see if the String of Parent is equal to newLogObjectId, a string?
    query1.whereKey("Parent", equalTo:newLogObjectId)

enter image description here

1 个答案:

答案 0 :(得分:1)

Parse中的指针不指向某个值,它们指向一个类(PFObject)。所以看起来你的名为Parent的指针指向Parse类NewLog。我假设您要检查的字符串是类NewLog中的字段。另外,要在查询中包含指针,请使用query1.includeKey("PointerName")。试试这个:

let newLogObjectId = objectIdArray[markerIndex]

let query1 = PFQuery(className: "ComparablePhotos")
query1.includeKey("Parent")
query1.findObjectsInBackgroundWithBlock({ (objects: [AnyObject]?, error: NSError?) -> Void in
    if (error == nil){
        if let comparablePhotos = objects as? [PFObject]{
            for photo in comparablePhotos {
                if let parentPointer:PFObject = photo["Parent"] as? PFObject{
                    if(parentPointer["columnWithString"] as! String == newLogObjectID){
                        // Do something
                    }
                }
            }
        }
    }else{
        println(error)
    }

})