gpt4 book ai didi

ios - '[AnyObject] ?' is not convertible to ' NSArray'(xcode,swift)

转载 作者:行者123 更新时间:2023-11-29 01:44:27 30 4
gpt4 key购买 nike

错误在 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
})
}

}
}

关于ios - '[AnyObject] ?' is not convertible to ' NSArray'(xcode,swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32085524/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com