斯威夫特&解析 - PFUser currentUser永远不等于零 [英] Swift & Parse - PFUser currentUser never equals nil
问题描述
我正在使用Xcode,Swift和Parse。当我尝试注销PFUser时,我永远不会得到零回报。
I am using Xcode, Swift, and Parse. When I try and logout a PFUser, i never get a return of nil.
在应用程序的这一部分中,viewController只显示一个登录的按钮。一个用户发送注册。一个发送用户更改详细信息,一个是简单的注销。
In this part of the app, the viewController is simply showing a few buttons one logs in. One sends the user to signup. One sends the user to change details, and one is a simple logout.
注销时两个重要的代码是;
The code for the two that matter on logout is;
@IBAction func logout(sender: AnyObject) {
PFUser.logOut()
var currentUser = PFUser.currentUser()
self.displayAlert("You are now logged out", error: "")
println(currentUser!)
}
@IBAction func changeDetails(sender: AnyObject) {
var currentUser = PFUser.currentUser()
println(currentUser!)
if currentUser != nil {
let nextView30 = self.storyboard?.instantiateViewControllerWithIdentifier("changeDetails") as! changeUserDetailsViewController
self.navigationController?.pushViewController(nextView30, animated: true)
} else {
self.displayAlert("Please log in", error: "")
}
}
一旦代码运行并且我注销,无论currentUser被读取到哪里,我都得到以下类型的响应,而不是nil。下一个ViewController被操作,如果没有usr登录就不会发生这种情况。
Once the code runs and I logout, wherever the currentUser gets read I get the following type of response, not nil. The next ViewController is actioned, and this shouldn't happen without a usr logged in.
PFUser:0x37018fbc0,objectId:new,localId:local_3b5eb7453f9af5ed {
}
PFUser: 0x37018fbc0, objectId: new, localId: local_3b5eb7453f9af5ed { }
我做错了什么还是这个标准?
如果它是正确的,我如何返回没有用户登录?
Am I doing something wrong or is this standard? If it is correct, how do I return no user logged in?
谢谢
推荐答案
我一直在努力退出一段时间,我相信我终于破解了它!
I've been struggling with logging out for a little while and I believe I have finally cracked it!
无论我做了什么,当我使用PFUser.logOut()时,永远不会将PFUser.currentUser()设置为nil,但它会将PFUser.currentUser()!。username设置为nil ...
No matter what I did, when I used "PFUser.logOut()" would never set "PFUser.currentUser()" to nil, but it would set "PFUser.currentUser()!.username" to nil...
因此我使用了
var currentUser = PFUser.currentUser()!.username
作为跟踪的全局变量是用户已登录。
as a global variable to track is a user is logged in.
在我的登录/首页上我添加了
On my login/first page I added
override func viewDidAppear(animated: Bool) {
if currentUser != nil {
self.performSegueWithIdentifier("login", sender: self)
}
}
最后在我使用的退出按钮上
and finally on my logout button i used
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "logout" {
PFUser.logOut() //Log user out
currentUser = PFUser.currentUser()!.username //Reset currentUser variable to nil
}
}
我希望有所帮助!
这篇关于斯威夫特&解析 - PFUser currentUser永远不等于零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!