2015-07-20 132 views
0

我正在做一個查詢,我正在檢查,看是否指針,「列」列中的值是否等於一個字符串,newLogObjectId。我顯然不能這樣做,因爲指針和字符串是不同的值類型,(返回nil)。當我查看Parse中的數據時,我注意到在Parent列中列出了objectId,但在一個按鈕中,單擊該按鈕時將加載NewLog類。
如何更改「Parent」是代碼「query1.whereKey(」Parent「,equalTo:newLogObjectId)」中的指針中的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] 

enter image description here

+0

is query1.whereKey(「Parent」,equalTo:newLog.ObjectId)not working?通常你通過.objectId,.username等等來訪問用戶名,objectId或你的對象所在的列。或者... query1.Parent.query.findobjectsInBackgroundwithBlock { –

+0

我會查詢NewLog類'whereKey(「objectId」, containedIn:objectIdArray)'獲取所有PFObject與關聯的對象ID。讓這個查詢獲取Parent字段,然後遍歷您的對象以獲取每個Parent。 – Connor

+0

沒有史蒂夫,它不工作。我相信如果它是Android,它會以這種方式工作。 –

回答

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) 
     } 
     } 
    } 

方法,因爲它讓你檢查錯誤,並且更容易將這些對象添加到你的數組中。

+0

我將如何抓住指針指針引用的行? –

+0

現在看到更新代碼,您可以在代碼中添加任何包含數據對象的數組 – Lamar

0

如果您只有objectId,請創建一個新的ParseObject,將其objectId設置爲newLogObjectId,然後在查詢中使用該新創建的對象(這是一個指針)。

var myNewLog = PFObject(className: "NewLog") 
myPointer.objectId = newLogObjectId 
query1.whereKey("Parent", myNewLog)