I am struggling for a while to assign the value returned by this function to a variable outside of it, in viewDidLoad but is returning an empty string. getUid() - is returning the firebase uid prRef - is calling the firebase table for users
Can someone tell me what am I doing wrong?
Thanks in advance,
var currentWorkplaceId: String?
func getCurrentWorkplaceId() -> String {
//completion:@escaping (Bool)->Void
var workplaceid = String()
prRef.child(getUid())
.child("workplace_id")
.observeSingleEvent(of: .value, with: { snapshot in
workplaceid = snapshot.value as! String
})
return workplaceid
}
usage:
currentWorkplaceId = getCurrentWorkplaceId()