在新的Firebase 4.0版本中获取数据库参考 [英] Get a database reference in the new Firebase 4.0 release

查看:57
本文介绍了在新的Firebase 4.0版本中获取数据库参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Firebase 3.0+中,获取数据库引用的方法如下:

In Firebase 3.0+ the method to get the database reference was as such:

var ref: FIRDatabaseReference!

ref = FIRDatabase.database().reference()


ref.child("rooms").observeSingleEventOfType(.Value, withBlock: { (snapshot) in

    if snapshot.hasChild("room1"){

        print("true rooms exist")

    }else{

        print("false room doesn't exist")
    }

})

在Firebase 4.0中,命名约定已更改,但我无法使其正常工作!?

In Firebase 4.0 the naming convention changed but I can't get it to work!?

var ref: DatabaseReference!    
ref = Database.database().reference()

还有其他人遇到过吗?

迅速的编译器建议从小写的数据库函数调用中删除().

The swift compiler is suggesting removing the () from the lowercase database function call

如果将其删除,则会引发错误消息:

if you remove it, it then throws the error message:

  • 数据库没有成员引用

那么您如何获得参考!!

So how do you get the reference then!?

Pod文件:

pod 'Firebase/Core'
pod 'Firebase/Database'

推荐答案

firebase文档需要更新. 1.将这两个都导入您的班级顶部

The firebase documentation needs to be updated. 1. import both of these at the top of your class

import FirebaseCore

import FirebaseDatabase

  1. 获取数据库引用仅在ViewDidLoad()中起作用

覆盖func viewDidLoad(){

override func viewDidLoad() {

super.viewDidLoad()
var ref: DatabaseReference!
ref = Database.database().reference()
}

这篇关于在新的Firebase 4.0版本中获取数据库参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆