我'm trying to load data from firebase into an array of Company objects, but it'不行 . 通过使用print语句,我注意到没有调用 viewDidLoad
方法和 observe
方法 . 除了一堆firebase文本(即"Firebase automatic screen reporting is enabled...")之外,没有任何内容可以打印到控制台 .
import UIKit
import FirebaseDatabase
class Information: UIViewController {
var ref:FIRDatabaseReference?
var databaseHandle:FIRDatabaseHandle?
var companiesInformation = [Company]() //holds name, booth, image
override func viewDidLoad() {
super.viewDidLoad()
print("viewDidLoad was called")
//Set firebase database reference
ref = FIRDatabase.database().reference()
// Retrieve posts and listen for changes
databaseHandle = ref?.child("companies").observe(.childAdded, with: { (snapshot) in
// Code that executes when child is added
let company: Company = Company()
company.name = snapshot.value(forKeyPath: "name") as! String
self.companiesInformation.append(company)
print("databaseHandle was called")
})
}
}
在使用可可 beans 荚下载Firebase和Firebase实时数据库后,我在App Delegate中添加了2个必要的Firebase代码,我的应用程序运行时没有错误 . 我只有2个黄色警告,如下所示:
那么为什么数据库不工作,为什么没有打印到控制台?
1 回答
这是一个愚蠢的错误 . 我意识到我在构建应用程序时没有调用信息视图控制器,因此没有调用
viewDidLoad
方法,因此没有打印任何内容 .