Search code examples
iosiphoneswiftfirebasedata-retrieval

Retrieving Data from Firebase to label 'Swift Project'


What's the correct syntax for the function that I should use to retrieve data from firebase to a label?

For Example, I want to retrieve the email and the password as in the picture here

I have tried this code bellow but it did not work! It retrieved no thing in the simulator!!

    ref.observeEventType(.Value, withBlock: {
        snapshot  in let m = snapshot.value.objectForKey("users/\(self.ref.authData.uid)/email") as? String
        self.EmailLabel.text = m

    })

Solution

  • Try This

    var ref = Firebase(url:"YOUR_URL_PATH/Users")
    
    ref.observeEventType(.Value, withBlock: { snapshot in
            let m = snapshot.value.objectForKey("Email")as?
            self.EmailLabel.text = m
    }, withCancelBlock: { error in
        println(error.description)
    })
    

    Hope this will help you...