Skip to content

Instantly share code, notes, and snippets.

@kutakmir
Created June 9, 2019 08:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kutakmir/07bf523d753bd583c0c4fa25c9e3538b to your computer and use it in GitHub Desktop.
Save kutakmir/07bf523d753bd583c0c4fa25c9e3538b to your computer and use it in GitHub Desktop.
How to save some data to the Firebase Database with a callback
Database.database().reference().child("myFantasticUniqueKey").setValue("some data") { (error: Error?, reference: DatabaseReference) in
if let error = error {
print("Error: \(error.localizedDescription)")
} else {
print("Success!")
}
}
// Unique auto ID
Database.database().reference().child("myFantasticCollection").childByAutoId().setValue("some data") { (error: Error?, reference: DatabaseReference) in
if let error = error {
print("Error: \(error.localizedDescription)")
} else {
print("Success!")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment