I'm trying to get access to the values stored in firebase dashboard to use them in different functions and methods in the class.
I used this method in this question
I have tried to print their values, the whole app has crashed and it gave me that their nil!
They are not nil actually! I used a similar method in viewDidLoad and I could retrieve the values to labels!
let refer = FIRDatabase.database().reference().child("UserDevices")
var globalEmail : String!
var globalPhone : String!
var globalImageUrl: String!
override func viewWillAppear(_ animated : Bool){
    super.viewWillAppear(animated)
    retrieveUserData{(email,phone,ImageUrl) in
        self.globalEmail = email
        self.globalPhone = phone
        self.globalImageUrl = ImageUrl
    }
}
func retrieveUserData(_ completionBlock : @escaping ((_ email : String?, _ phone : String?, _ ImageUrl: String?)->Void)){
    refer.child(byAppendingPath: self.strUserid as String).observe(.value , with: {snapshot in
        if let userDict =  snapshot.value as? [String:AnyObject]  {
            completionBlock(userDict["email"] as! String, userDict["phone"] as! String, userDict["ImageUrl"] as! String)
        }
    })
}
var strUserid : NSString!
override func viewDidLoad() {
    super.viewDidLoad()
    print(globalEmail)
    print(globalImageUrl)
    print(globalPhone)
    self.navigationController?.navigationBar.tintColor = UIColor.white
    print("idis \(self.strUserid)")
     let ref = FIRDatabase.database().reference().child("UserDevices")
     self.navigationController?.navigationBar.tintColor = UIColor.white
    ref.child(byAppendingPath: self.strUserid as String).observe(.value, with: { snapshot in
        if let dict = snapshot.value as? NSMutableDictionary{
            print("dict is \(dict)")
            if let Provider = dict["name"] as? String
            {
                self.DeviceDetailsProvider.text = Provider
               // self.navigationItem.title = Provider
            }
            if let name = dict["DeviceName"] as? String
            {
                self.DeviceDetailsName.text = name
                self.navigationItem.title = name
            }
            if let ShortDescription = dict["Description"] as? String
            {
                self.DeviceDetailsDescription.text = ShortDescription
            }
            if let City = dict["city"] as? String
            {
                self.DeviceDetailsCity.text = City
            }
        }
    })
   self.DeviceDetailsImageView.downloadedFrom(link: globalImageUrl)
}
Why I'm getting a crash here!
 
     
    
