有几天我试图破解为什么我的代码无法正常工作,而且我尝试的所有内容都没有给我任何结果。继承人: 有一个Booking类,其中包含进行预订的userFrom
let query = PFQuery(className: "Booking")
query.whereKey("offer", equalTo: offer.pfObject!)
if self.typeOfUser == .COOK { //! If user is a Cook
query.findObjectsInBackgroundWithBlock({ (objects : [PFObject]?, error : NSError?) -> Void in
if let error = error {
print(error.localizedDescription)
} else {
if let objects = objects {
self.bookings = objects
self.usersIds = [String]()
for object in objects {
let userFrom = object.objectForKey("userFrom") as? PFObject
let userId = userFrom!.objectId! as String
self.usersIds.append(userId)
}
self.getUserInfoForBooking()
} else {
print("Something went wrong")
}
}
})
}
我从每个用户获得objectId并将其附加到[String]数组。然后我用他们的ID查询用户
private func getUserInfoForBooking() {
let userQuery = PFQuery(className: "User")
userQuery.whereKey("objectId", containedIn: self.usersIds)
userQuery.findObjectsInBackgroundWithBlock({ (objects : [PFObject]?, error : NSError?) -> Void in
if let error = error {
print(error.localizedDescription)
} else {
print(objects!)
if let objects = objects {
for object in objects {
self.users.append(object)
}
self.collectionView.reloadData()
}
}
})
}
在这个查询中,我总是得到一个空数组。 无论我做了什么,无论我改变了什么总是[]回应:(
答案 0 :(得分:1)
这是查询用户的错误方法
let userQuery = PFQuery(className: "User")
因为类名是私有的。您应该将查询创建为
let userQuery = PFUser.query()