Reputation: 25
I just started learning Swift and I have an issue with writing into my Real Time Database. I followed the Firebase docs but still have this problem.
Here is my View Controller:
import UIKit
import FirebaseDatabase
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
var ref: DatabaseReference! = Database.database().reference()
self.ref.child("Produkt/Kappe/Laden").setValue("Netto") //this is where I am getting the error: "Expected declaration"
}
Please help. Thanks
Upvotes: 0
Views: 111
Reputation: 1002
Use this inside viewdidload or any function because you cannot perform these actions outside function scope
Try this
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.ref.child("Produkt/Kappe/Laden").setValue("Netto")
}
var ref: DatabaseReference! = Database.database().reference()
}
you cannot do this outside any function.
Upvotes: 2