Okay thanks for the response
Post not yet marked as solved
Apparently I had set the data incorrectly. It builds now, reading:guard let userId = authResult?.user else { return }
let userData: [String: Any] = [
"firstName" : "",
"User ID" : userId,
"dateCreated" : FieldValue.serverTimestamp(),
]
let db = Firestore.firestore()
db.collection("users").document("one").setData(userData) { err in
if let err = err {
print("Error writing document: \(err)")
} else {
print("Document successfully written!")
}
}
}
}
}But, it crashes and gives a runtime error:@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate { //error:
//libc++abi.dylib: terminating with uncaught exception of type NSException
//(lldb)
//3 comments above all one lineDo you know what this crash means?
Post not yet marked as solved
Thanks I fixed that and also found that I was trying to assign the textField object to the password inside dictionary. Those corrections have eliminated the errors but the IBAction isn't working. It recognizes the tap (gives the "login button tapped" message) but doesn't actually login the user and go to the next segue.(EDIT): I've taken a new approachHere's what I have now:import UIKit
import Firebase
class SignUpViewController: UIViewController {
//Outlets
@IBOutlet weak var firstNameText: UITextField!
@IBOutlet weak var lastNameText: UITextField!
@IBOutlet weak var emailText: UITextField!
@IBOutlet weak var passwordText: UITextField!
@IBOutlet weak var signUpButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func signUpButtonTapped(_ sender: Any) {
guard let firstName = firstNameText.text,
let lastName = lastNameText.text,
let email = emailText.text,
let password = passwordText.text else { return }
Auth.auth().createUser(withEmail: email, password: password) { (authResult, error) in
if let error = error {
debugPrint("Error creating user: \(error.localizedDescription)")
}
let changeRequest = Auth.auth().currentUser?.createProfileChangeRequest()
changeRequest?.displayName = firstName
changeRequest?.commitChanges(completion: { (error) in
if let error = error {
debugPrint(error.localizedDescription)
}
})
guard let userId = authResult?.user else { return }
Firestore.firestore().collection(USERS_REF).document(userId).setData([
USERNAME : firstName,
DATE_CREATED : FieldValue.serverTimestamp()
], completion: { (error) in
if let error = error {
debugPrint(error.localizedDescription)
} else {
self.dismiss(animated: true, completion: nil)
}
})
}
}
}After fixing the previous errors, I get a new error:Cannot invoke 'setData' with an argument list of type '([String : Any], completion: ((Error?) -> Void)?)' (line 37)I'm not sure why it's doing this. Any idea why I'm getting this error?