Search code examples
iosswiftpfuser

PFUser.currentUser() never equals nil


I'm getting a strange behavior with Swift and Xcode 7. This didn't happen on Xcode 6. I have disabled Anonymous users on Parse. I have logged out the current user. Every time I come back to the login screen...whether I logout the user in the background or even if i logout and then restart the app the PFUser.currentUser() never equals nil. It always allows the user to get to the main screen. I have even tried to logout the user right before the following statement is execute, but PFUser.currentUser() still not nil!

Anyone having the same problem? This started happing after the update.

if PFUser.currentUser() != nil {
                // Do stuff with the user
                let storyboard = UIStoryboard(name: "main", bundle: nil)
                let controller = storyboard.instantiateViewControllerWithIdentifier("mainVC")
                self.presentViewController(controller, animated: true, completion: nil)

            }

Solution

  • Try this out:

    var currentUser = PFUser.currentUser()?.username
    
    if currentUser != nil {
        // Do your stuff here
    }