[英]'[AnyObject]?' is not convertible to 'NSArray'(xcode,swift)
該錯誤發生在let USER:PFUser
...工作正常,但是當我更新Xcode時出現了此問題。 用戶名名稱未顯示。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let postcells: postsTableViewCell = tableView.dequeueReusableCellWithIdentifier("PostCell", forIndexPath: indexPath) as! postsTableViewCell
let Post:PFObject = self.PostData.objectAtIndex(indexPath.row) as! PFObject
postcells.postTimetextView.text = Post.objectForKey("Content") as! String
var dateFormatter:NSDateFormatter = NSDateFormatter()
dateFormatter.dateStyle = NSDateFormatterStyle.NoStyle
dateFormatter.timeStyle = NSDateFormatterStyle.ShortStyle
postcells.timeStamp.text = dateFormatter.stringFromDate(Post.createdAt!)
var findPostedBy:PFQuery = PFUser.query()!
findPostedBy.whereKey("objectId", equalTo: Post.objectForKey("Postedby")!)
findPostedBy.findObjectsInBackgroundWithBlock{
(objects, error) -> Void in
if error == nil {
let USER:PFUser = (objects as NSArray).lastObject as! PFUser
postcells.usernameLabel3.text = USER.username
}
}
return postcells
}
您需要確保從解析返回了數組
您可以使用此:
findPostedBy.findObjectsInBackgroundWithBlock{
(objects, error) -> Void in
if error == nil {
if objects?.count > 0 {
let USER:PFUser = objects!.last as! PFUser
// Avoid updating the UI on a background thread
dispatch_async(dispatch_get_main_queue(), { () -> Void in
postcells.usernameLabel3.text = USER.username
})
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.