Reputation: 25
I would like to add a document to my database collection using autoid with fields that I assign the name to in swift ui .
Upvotes: 1
Views: 908
Reputation: 1812
Get a reference of the database:
var db: Firestore!
then you can reference it with:
db.collection()
For example, if I wanted to add a person's name under a unique id:
db.collection("users").addDocument(data: [
"name": nameTextField.text // Change this to the variable you want to save
]) { err in
if let err = err {
print("Error writing document: \(err)")
} else {
print("Document successfully written!")
}
}
If you create the document without an explicit Id, our SDK will auto-generate a random one for you.
The docs are a good source of information too.
Upvotes: 4