2015-07-19 46 views
1

我正在做一个查询,并且正在检查列“Parent”(它是一个指针)中的值是否等于字符串newLogObjectId。我显然不能这样做,因为指针和字符串是不同的值类型,(返回nil)。如何将字符串与指针中的字符串进行比较?解析中的查询指针(ios)

//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

指针在解析不点的值,它们指向一个类(一个PFObject)。所以它看起来像名为Parent的指针指向解析类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) 
    } 

}) 
+0

谢谢,我试过了,但NewLog正在抛出一个错误。 “使用未声明的类型NewLog” –

+0

谢谢。我还有一个关于parentPointer的错误....它的“使用未解析的标识符”parentPointer'“ –

+1

必须删除第一次编辑时的变量声明,我的错误!这现在应该适合你。 –