Firebase checking for null value (Swift)

Viewed 6968

I'm running the code below to see if a user that opens the app is already logged in, and then to check if they've set up a profile. I'm having trouble checking for the null value value returned from the profile check

override func viewDidLoad() {
    super.viewDidLoad()

    //Check to see if user is already logged in
    //by checking Firebase to see if authData is not nil
    if ref.authData != nil {

        //If user is already logged in, get their uid.
        //Then check Firebase to see if the uid already has a profile set up
        let uid = ref.authData.uid
        ref.queryOrderedByChild("uid").queryEqualToValue(uid).observeSingleEventOfType(.Value, withBlock: { snapshot in
                let profile = snapshot.value
                print(profile)
        })

In the last line when I print(profile), I either get the profile information, or

 <null>

how do i check for this value?

 if profile == nil 

does not work

If I do

let profile = snapshot.value as? String

first, then it always returns nil even if there is a snapshot.value

2 Answers
Related