0
@IBAction func addPost(_ sender: Any) {
    ref?.child("Posts").childByAutoId().setValue(titleText.text)
}

What if I wanted to add subsections to post instead of just the title. Like date, authors, etc.

0

1 Answer 1

8

Create a regular Swift dictionary, set the desired properties, and then call setValue using the same syntax as above.

For instance:

let ref: FIRDatabaseReference = ...
let post = [
    "title":  "Incompleteness Theorem", 
    "author": "Kurt Gödel",
    "date":   "1931"
]
ref.child("Posts").childByAutoId().setValue(post)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.