xcode Firebase 引用未声明
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38523375/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Firebase References undeclared
提问by ffritz
I created a new Xcode project, added the 'Firebase' pod to my pod file and installed it, and added the Google-services.plist file and the rest according to the Firebase documentation.
我创建了一个新的 Xcode 项目,将“Firebase”pod 添加到我的 pod 文件并安装它,并根据 Firebase 文档添加了 Google-services.plist 文件和其余文件。
import Firebaseworks fine, but if I try
导入 Firebase工作正常,但如果我尝试
var ref:FIRDatabaseReference!
in the same ViewController, then it throws an error:
在同一个 ViewController 中,它会抛出一个错误:
Use of undeclared type 'FIRDatabaseReference'
使用未声明的类型“FIRDatabaseReference”
And this happens for any Firebase References. Any ideas on this? I am very new to Swift and the xCode IDE.
任何 Firebase 引用都会发生这种情况。对此有何想法?我对 Swift 和 xCode IDE 非常陌生。
回答by proformance
Just had the same problem, but after a while I realized that I was missing an entry in the pod-file, your pod-file should contain:
刚刚遇到了同样的问题,但过了一会儿我意识到我在 pod 文件中丢失了一个条目,您的 pod 文件应该包含:
pod 'Firebase/Database'
Hope it works now :)
希望它现在有效:)
回答by Mike Yan
EDIT: I found the real problem behind. Firebase had update. User need to update the firebase version via cocopod. After update the cocopod, can use everything normally same as firebase Doc.
编辑:我发现了背后的真正问题。Firebase 有更新。用户需要通过 cocopod 更新 firebase 版本。更新 cocopod 后,可以正常使用与 firebase Doc 相同的所有内容。
==========================================
==========================================
I have the same problem, but cannot fix it by updating the pod-file.
我有同样的问题,但无法通过更新 pod 文件来修复它。
Finally, I find out a solution.
最后,我找到了解决方案。
Google teach us to import only
谷歌教我们只导入
import Firebase
导入 Firebase
Just add:
只需添加:
import FirebaseDatabase
导入 Firebase 数据库
and everything will become fine
一切都会好起来的
回答by vijay kahar
In your Podfile, add pod
在您的 Podfile 中,添加 pod
pod 'Firebase/Database'
Then import Firebase Database in your ViewController
然后在您的 ViewController 中导入 Firebase 数据库
import FirebaseDatabase
Create a globle var ref
that you can use it anywhere in viewcontroller
创建一个var ref
可以在 viewcontroller 中的任何地方使用它的 glob
var ref: DatabaseReference!
Now, In viewDidLoad
Define the ref
现在,在viewDidLoad
定义ref
ref = Database.database().reference()
回答by Kelvin Tan
On your Podfile, add additional line of
在您的 Podfile 上,添加额外的行
pod 'Firebase/Database'
Then on your code section
然后在你的代码部分
import FirebaseDatabase
And it should work now, with the following code:
它现在应该可以工作了,代码如下:
var ref: DatabaseReference!
回答by Ummar Ahmed
Problem solved by removing "FIR"
form the words ("FIRDatabaseReference" and "FIRDatabaseHandle")
通过删除"FIR"
单词来解决问题("FIRDatabaseReference" and "FIRDatabaseHandle")
Also that import "Firebase" in the viewController
同样在 viewController 中导入“Firebase”
回答by raj
As in swift4 the 'FIRDatabaseReference' has been renamed to 'DatabaseReference'
与 swift4 一样,“FIRDatabaseReference”已重命名为“DatabaseReference”
So, use:
所以,使用:
var ref:DatabaseReference!
变量引用:数据库引用!