1

I am doing a query and I am checking to see if the value in the column "Parent", which is a pointer, is equal to a string, newLogObjectId. I obviously cannot do this since a pointer and a string are a different value type, (returns nil). How do I compare a string to a string in a pointer?

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

1

Pointers in Parse don't point to a value, they point to a class (a PFObject). So it looks like your pointer named Parent is pointing to the Parse class NewLog. I'm assuming then the string you are wanting to check is a field in the class NewLog. Also, to include the pointer in the query, use query1.includeKey("PointerName"). Try this:

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

})
Sign up to request clarification or add additional context in comments.

9 Comments

Thanks, I tried, but NewLog is throwing an error. "Use of undeclared type NewLog"
Thank you. I have one more error regarding parentPointer.... its "use of unresolved identifier 'parentPointer'"
Must've deleted the variable declaration on my first edit, my mistake! This should work for you now.
It might not know right offhand that it is dealing with a String. Try parentPointer["columnWithString"] as! String == newLogObjectId
The Images column is part of the class ComparablePhotos, which you grab at the line if let comparablePhotos = objects as? [PFObject]. Then in the next line you grab each individual object inside your class. So once you edit that item, here called photo, just do a photo.save() before you grab the next photo.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.