如何在 PFUser 登录后检索 ObjectID?
How to retrieve ObjectID after PFUser login?
PFUser.logInWithUsernameInBackground(fullName.text, password: password.text) {
(user: PFUser!, error: NSError!) -> Void in
if user != nil {
self.loginButton.enabled = false
self.helpButton.enabled = false
self.objectID = self.PFUser.objectId
}
}
我需要用户登录后的 objectID。我知道如何检索 PFObject 的 objectID,当涉及到 PFUser 时我得到一个错误(在上面的代码的最后一行)。我怎样才能得到id?
您正在使用 self.PFUser.objectId
,但我认为您指的是从完成块返回的 user
。所以尝试:
self.objectID = user.objectId
在最后一行。
您应该使用 user.objectId
或 PFUser.currentUser().objectId
而不是 self.PFUser.objectId
:
self.objectID = user.objectId
self.objectID = PFUser.currentUser().objectId
PFUser.logInWithUsernameInBackground(fullName.text, password: password.text) {
(user: PFUser!, error: NSError!) -> Void in
if user != nil {
self.loginButton.enabled = false
self.helpButton.enabled = false
self.objectID = self.PFUser.objectId
}
}
我需要用户登录后的 objectID。我知道如何检索 PFObject 的 objectID,当涉及到 PFUser 时我得到一个错误(在上面的代码的最后一行)。我怎样才能得到id?
您正在使用 self.PFUser.objectId
,但我认为您指的是从完成块返回的 user
。所以尝试:
self.objectID = user.objectId
在最后一行。
您应该使用 user.objectId
或 PFUser.currentUser().objectId
而不是 self.PFUser.objectId
:
self.objectID = user.objectId
self.objectID = PFUser.currentUser().objectId