I currently have a button on one of my View Controllers which once selected, should display a UIAlertController which allows the user to enter in some text. I have created a segue between the button and the Swift file, however once the button is selected, my Alert Controller isn't appearing. Here is my code:
import UIKit
import FirebaseAuth
import Firebase
class OnlineAccountsViewController: UIViewController {
@IBAction func editEbayName(_ sender: Any) {
let ac = UIAlertController(title: "Edit your Ebay name", message: "Please enter your new Ebay name", preferredStyle: .alert)
ac.addTextField()
ac.addAction(UIAlertAction(title: "Cancel", style: .default))
let submitAction = UIAlertAction(title: "Submit", style: .default) { _ in
if let answer = ac.textFields?.first?.text {
let db = Firestore.firestore()
let user = Auth.auth().currentUser
db.collection("users").getDocuments { (snapshot, error) in
if let error = error {
print(error)
return
} else {
for document in snapshot!.documents {
let data = document.data()
let userId = data["uid"] as! String
if userId == user?.uid {
document.reference.updateData([
"ebayname":(answer)
])
}
}
}
}
}
}
}
Any ideas as to why this is happening and how to get it working would be appreciated.
add self.present(ac, animated: true, completion: nil)