user2312844
user2312844

Reputation: 17

Getting empty username string

var query = PFQuery(className:"FriendRequest")
        query.whereKey("receiver", equalTo: PFUser.currentUser())
        query.findObjectsInBackgroundWithBlock {
            (objects: [AnyObject]?, error: NSError?) -> Void in
            if let objects = objects as? [PFObject] {
                self.friendRequestArray = objects
                let user = self.friendRequestArray[0]["sender"] as PFUser
                println(user.username) //prints blank string.
                self.tableView.reloadData()
            }
        }

Hello, why is my println(user.username) printing nothing in this scenario? There are numerous objects in the array and ["sender"] points to a valid user.

What is going on?

edit: self.friendRequestArray is initialized earlier as [PFObject]() edit2: No error is occurring either, since the error object is nil.

Upvotes: 1

Views: 38

Answers (1)

picciano
picciano

Reputation: 22701

Add query.includeKey("sender") before you call findObjectsInBackgroundWithBlock.

Upvotes: 2

Related Questions