0

I am trying to make an app that uses firebase for authentication and database. This is my first app using firebase and I am unable to save files to firebase database. I am not getting any error in the console when I run the app but it is not saving anything to firebase. I read the firebase docs and followed the instruction but I am unable to get it to work. Help would be appreciated. Here is my code import UIKit import Firebase import FirebaseDatabase

class AddVC: UIViewController {

 var refAttractions: DatabaseReference! //defining firebase database reference

@IBOutlet weak var addedlbl: UILabel!
@IBOutlet weak var descriptioninfo: UITextField!
@IBOutlet weak var categoryinfo: UITextField!

override func viewDidLoad() {
    super.viewDidLoad()

        // accessing nodes of refAttractiions
     refAttractions = Database.database().reference().child("Attractions")

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@IBAction func submitbtn(_ sender: Any) {
    addAttractions()
}
func addAttractions(){
    let key = refAttractions.childByAutoId().key //creating id for the  attraction. 
    let attraction = ["id": key,
                      "category": categoryinfo.text! as String,
                      "description": descriptioninfo.text! as String ]

    refAttractions.child(key).setValue(attraction)
 }



@IBAction func backbtn(_ sender: Any) {
    dismiss(animated: true, completion: nil)
    }
}

Also, I have changed the rules in my firebase database to true for both read and write. Any help would be appreciated.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
josh n
  • 23
  • 5

0 Answers0