我正在尝试获取PFUser的用户名。下面的代码不使用此行:var username = nameId.username as String
但添加时,集合视图不会显示任何结果。
有什么想法吗?
var query = PFQuery(className:"Chat")
// query.whereKey("user", equalTo:currentUser)
query.whereKey("rideId", equalTo:currentObjectId)
query.orderByAscending("createdAt")
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]!, error: NSError!) -> Void in
if error == nil {
// The find succeeded.
NSLog("Successfully retrieved \(objects.count) scores.")
// Do something with the found objects
for object in objects {
NSLog("%@", object.objectId)
var testId = object.objectId
println(testId)
self.orderedIdArray.append(testId)
var message = object.objectForKey("message") as String
self.messageString = message
self.messageArray.append(self.messageString)
println(message)
var nameId = object.objectForKey("user") as PFUser
var username = nameId.username as String
self.nameString = username
self.namesArray.append(self.nameString)
self.collectionView?.reloadData()
}
} else {
// Log details of the failure
NSLog("Error: %@ %@", error, error.userInfo!)
}
}
答案 0 :(得分:1)
现在正在使用这一行:
query.includeKey("user")