0

I'm having nightmares with this.

I have one Parse Class named Transactions which has 3 pointers to each class:

enter image description here

Here is the Class User

enter image description here

Now what I'm trying to do is a CustomTableView that shows all the Transactions and I want to put the Username inside the cell. Like This:

enter image description here

The problem is that I can't find the right query to get this information using those pointers. Nothing works...What query give me the username of that transaction? Thank you

1 Answer 1

1

If you're looking for all the transactions:

var query = PFQuery(className:"Transaction")
query.includeKey("PointerUser")
query.findObjectsInBackgroundWithBlock {
    (objects: [AnyObject]?, error: NSError?) -> Void in

    if error == nil {
        // The find succeeded.
        println("Successfully retrieved \(objects!.count) scores.")
        // Do something with the found objects
        if let objects = objects as? [PFObject] {
            for object in objects {
                //because we used the include key command
                //we can now access the user associated with PointerUser
                println(object["PointerUser"]["Username"])
            }  
        }
    } else {
        // Log details of the failure
        println("Error: \(error!) \(error!.userInfo!)")
    }
}
Sign up to request clarification or add additional context in comments.

5 Comments

Interesting...This may solve my problem, but i get this error: "Cannot subscript a value of type 'AnyObject?' with an index of type 'String'" at "Println"
I have solved the problem with " println(object["PointerUser"]?["Username"])" Is that ok?
I have used your code to pass the objects into an array named queryArray. How can I access "pointerUser.username"?
Just loop through queryArray and for each object, "object," use ["PointerUser"]["Username"], just like before.
Can you take a look? pastebin.com/PbtcjQ7v As it is, give me an error when ["PointerUser"]["Username"] "Cannot assign a value of type 'AnyObject??' to a value of type 'String?'" (I can open a new question if you want) Thank you for you help :)

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.