I am creating an app and am using Firebase for my backend and user authentication. I complete the login process in the View Controller for the login screen. After doing so, the authData object is created in that VC, and the authData object contains a UID (user id) field. I would like to reference the uid field of the same object in another VC, in which I change the root database url by appending the myRootRef variable created in the FirebaseFramework.m file. Essentially, I am looking to be able to use and reference an object created in one VC in another VC. How can I do this?
In the login VC:
@IBAction func LoginTapped(sender: UIButton) {
var email:NSString = txtEmail.text as NSString
var password:NSString = txtPassword.text as NSString
if ( email.isEqualToString("") || password.isEqualToString("") ) {
var alertView:UIAlertView = UIAlertView()
alertView.title = "Sign in Failed!"
alertView.message = "Please enter Email and Password"
alertView.delegate = self
alertView.addButtonWithTitle("OK")
alertView.show()
} else {
myRootRef.authUser(email as String, password: password as String){
error, authData in
if error != nil {
var alertView:UIAlertView = UIAlertView()
alertView.title = "Sign in Failed!"
alertView.message = "Incorrect email or password"
alertView.delegate = self
alertView.addButtonWithTitle("OK")
alertView.show()
} else {
println(authData.uid)
}
}
}
}
in the other VC:
@IBAction func SubmitTapped(sender: AnyObject) {
var UserRef = myRootRef.childByAppendingPath(authData.uid)
UserRef.setValue(item)
}
In the other VC, "authData.uid" isn't recognized, although it is created in the login VC.