1
votes
if  var findPublisher:PFQuery = PFUser.query(){
    findPublisher.whereKey("objectId", equalTo:quote.objectForKey("publisher").objectId)//error here
    }

I am getting an error Value of any optional type 'Any Object'? not unwrapped. I don't know what i have done incorrectly. I am a beginner so please bear with me:)

2
Are you trying to use the current logged in user in Parse, or any user out of the database? - Tillson
current user logged in Parse - Abhishek Mahesh

2 Answers

0
votes

This is really a place where you would give each quote a pointer to a user object, and then you could just get the publisher of the quote without an extra query. But if you want to do it this way, you would do:

let query = PFUser.query()!
query.whereKey("objectId", equalTo: (quote["publisher"] as! String)) // You can unwrap it as long as you are sure that quote is not nil, and the publisher is set.
query.getFirstObjectInBackgroundWithBlock({ (user: PFObject?, error: NSError?) in 
  // check for errors and use the object
})

This way of doing it also creates Parse security issues, as anyone with your app's ID and key can get a full user list.

0
votes
let findPublisher = PFUser.query()!
    findPublisher.whereKey("objectId", equalTo: (quote["publisher"] as! String))
        findPublisher.findObjectsInBackgroundWithBlock{
            (objects:[AnyObject]?, error:NSError?)->Void in

            if error == nil{
                let user:PFUser = (objects as NSArray).lastObject as! PFUser//error here
                cell.publisherLabel.text = user.username
        }
    }

I end up getting an error that says that AnyObject is not convertible to NSArray?