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)
}
})
}
答案 0 :(得分:2)
问题似乎在于您如何声明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
}