Swift3 - Get variable outside scope?

Hi,

I want to get the name and address from users in Firebase Database and write them back to Firebase in a different child.

I´m using this code to get the information I need:

`override func viewDidLoad() {
super.viewDidLoad()
ref = Database.database().reference()
let user = Auth.auth().currentUser!.uid

    //Read data from Firebase
   ref?.child("users").child(user).observeSingleEvent(of: .value, with: { (snapshot) in
    
        guard let userDict = snapshot.value as? [String: Any],
            let address = userDict["Address"] as? String,
            let name = userDict["Name"] as? String else {
                return
        }
        
        print(address + name)
    
    
    })
    
    
}`

That is working fine, but I want to write the values back when a button is pushed. And I can’t figure out how to access the variables outside the scope?
I´m sure this is a elementary question, but I will be very grateful for any help in the matter.