TheRealRonDez
TheRealRonDez

Reputation: 2807

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)

            }

Upvotes: 0

Views: 638

Answers (2)

Kegham K.
Kegham K.

Reputation: 1614

It is better to use the objectId of the user instead of the username because the username could be changed but objectId can never change.

    let currentUser = PFUser.currentUser()?.objectId
if currentUser != "" {

}

Upvotes: 0

Abhinav
Abhinav

Reputation: 38162

Try this out:

var currentUser = PFUser.currentUser()?.username

if currentUser != nil {
    // Do your stuff here
}

Upvotes: 3

Related Questions