Home>

Swift beginner. An error occurred when retrieving data from firestore.
Please check the following.

let defaultstore: Firestore!
defaultstore = Firestore.firestore ()

let docRef = defaultstore.collection ("user_info"). document (userEmail!)

docRef.getDocument {(document, error) in
if let document = document, document.exists {
let dataDescription = document.data (). map (String.init (describing :)) ??"nil"
print ("Document data: \ (dataDescription)")
} else {
print ("Document does not exist")
}
}

print (dataDescription)
Error =>"Use of unresolved identifier'dataDescription'"

There is data in'dataDescription'printed in the if statement.
An error will be displayed if'dataDescription'is printed outside the if statement. Why?