How can I access my array objects in another function, array objects from arr and from emails. I can so far only access my array objects inside of the else statement when I call auth.auth() function. I want to find out how I can do this.
let store = CNContactStore()
store.requestAccess(for: .contacts) { (granted, err) in
if let err = err{
print(err.localizedDescription)
return
}
if granted{
print("Access granted")
let keys = [CNContactGivenNameKey, CNContactFamilyNameKey, CNContactEmailAddressesKey]
let req = CNContactFetchRequest(keysToFetch: keys as [CNKeyDescriptor])
do {
try store.enumerateContacts(with: req) { (contact, stop) in
print(contact.emailAddresses.first?.value as Any)
if let em = contact.emailAddresses.first?.value{
//print("cool")
Auth.auth().fetchProviders(forEmail: em as String, completion: {
(providers, error) in
if error != nil {
print("wierd")
}else{
if providers == nil{
print("No active account")
}else{
self.emails.append(em as String)
self.arr.append(contact.givenName + " " + contact.familyName)
print("Active Account")
print(self.arr)
print(self.emails)
}
}
})
}else{
//print("wow")
}
}
}catch let err{
print(err.localizedDescription)
}
}else{
print("Access denied")
}
}
print("Arr")
print(self.arr)
print(self.emails)
print("Emails")
I want to find out how I can access my array elements in "arr" and in "emails" in another function, because my ultimate goal is to put out the array info in a tableView.