从哪里可以在iOS上从Firebase添加数据库引用?
我正在通过此链接关注在iOS应用程序上安装和设置实时数据库的说明,我很困惑在我的应用程序中在xcode中添加语句self.ref = FIRDatabase.database().reference()
。 哪个文件或位置?
Firebase 4.0及更高版本:确保将以下内容添加到Podfile中! 在我添加此内容之前,我遇到了与您相同的问题(在Firebase安装教程的上一页中找到)。
pod 'Firebase/Database'
如果你像我一样,你会忽略它,因为你认为你已经在Firebase设置教程中添加了这一行,但是在设置中添加的行是:
pod 'Firebase/Core'
添加后,它应该工作。 通用视图控制器如下所示:
import Firebase import FirebaseDatabase class GenericViewController: UITableViewController { var ref: DatabaseReference! override func viewDidLoad() { super.viewDidLoad() ref = Database.database().reference() } }
这让我陷入了一段时间 – 我希望这会有所帮助! 🙂
以下是代码。
import UIKit import Firebase import FirebaseAuthUI class ExampleVC: UIViewController, UINavigationControllerDelegate { var ref: FIRDatabaseReference! override func viewDidLoad() { super.viewDidLoad() //if user is signed in configureDatabase() } func configureDatabase() { //Gets a FIRDatabaseReference for the root of your Firebase Database. ref = FIRDatabase.database().reference() } }
在appDelegate文件中定义变量如下(全局)
var ref: FIRDatabaseReference!
在Appdelegate文件中添加上述语句( DidfinishlaunchingwithOption
方法),以便在应用程序启动时初始化数据库。
self.ref = FIRDatabase.database().reference()
- 在此之后添加与fire base相关的所有其他方法或所有语句。
说明不清楚。 为了使您能够在AppDelegate中为’ref’赋值,您必须首先声明’ref’属性,因为当前不存在。
使用您的属性声明将它放在AppDelegate中:
var ref: FIRDatabaseReference!
然后将该行放在applicationDidFinishLaunching方法的文档中,您的代码将被编译。 是否要在AppDelegate中保留该属性是一个不同的问题。
- 以编程方式将Sqlite表数据导出到csv文件 – xcode iOS 5(适用于ipad应用)
- 使用Swift(Pre Swift 3)通过引用调用与按值调用
- 如何使用commitEditingStyle从plist删除数组?
- 我可以从UIActivityViewController和原生UIActivityTypePostToTwitter微博animationGIF吗?
- Xcode 5命令行:针对架构“arm64”的无效部署目标“3.0.0”
- iOS 7很慢,用UIPickerView打开UITableViewController
- 如何在OS X 10.8.4上为iOS模拟器(6.1)编译Boost 1.54.0(1.54)?
- 发送到实例的Swift无法识别的select器 – 我错过了什么?
- 在切换视图时保持xcode中的滑块位置