gpt4 book ai didi

ios - 解析查询不起作用

转载 作者:行者123 更新时间:2023-11-28 13:03:24 25 4
gpt4 key购买 nike

这给我一个错误。我附上了错误的截图。 enter image description here

class UserTableViewController: UITableViewController {
var users = [""]

override func viewDidLoad() {
super.viewDidLoad()

//Printing the currentUser name
print(PFUser.currentUser()!)

var query = PFUser.query()

query!.findObjectsInBackgroundWithBlock({ (objects : [AnyObject]!, error : NSError!) -> Void in
self.users.removeAll(keepCapacity : true)

for object in objects {
var user : PFUser = object as PFUser

self.users.append(user.username)
}
})
}

最佳答案

问题似乎在于您如何声明您的 users 数组。试试这个。

class UserTableViewController: UITableViewController {
var users = [String]()

override func viewDidLoad() {
super.viewDidLoad()

//Printing the currentUser name
print(PFUser.currentUser()!)

var query = PFUser.query()

query!.findObjectsInBackgroundWithBlock({ (objects : [AnyObject]!, error : NSError!) -> Void in
self.users = [String]()

if let parseUsers = objects as? [PFUser] {
for u in parseUsers {
//parseUsers is now an array of PFUser
self.users.append(u.username)
}
}
})
}

你也不能这样投你的用户。试试这个:

if let parseUsers = objects as? [PFUser] {
//parseUsers is now an array of PFUser
}

关于ios - 解析查询不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33351235/

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