iosswiftparse-platformpfuser

PFUser.current() always returns nil


In the viewDidLoad() of the Initial View Controller in my app I run this:

let currentUser = PFUser.current()

        if currentUser != nil{

        self.performSegue(withIdentifier: "toTabs", sender: self)
    }

currentUser is always nil.

I run PFUser.enableAutomaticUser() in the AppDelegate.Swift after I configure the parse client as per the latest parse server Ios SDK. This should make it so that when ever a user is logged in they stay logged in unless a logout command is run. I have no idea why this isn't happening.


Solution

  • After much debugging, I realized that PFUser.enableAutomaticUser() was functioning normally. The problem was that the self.performSegue(withIdentifier: "toTabs", sender: self) wasn't dispatched to the main queue. I fixed this by changing my code to:

     let currentUser = PFUser.current()
    
        if currentUser?.username != nil{
    
            print(currentUser!)
    
            DispatchQueue.main.async(){
    
            self.performSegue(withIdentifier: "toTabs", sender: self)
    
            }
    
        }else{
    
            print("No current User")
      }
    

    Thanks, to all of you for your help, and I'm sorry to have wasted your time with this.