首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >数据库引用错误

数据库引用错误
EN

Stack Overflow用户
提问于 2018-02-25 06:38:34
回答 3查看 435关注 0票数 0

在我的iOS项目中,我使用Firebase创建了一个实时数据库。我已经在AppDelegate.swift中使用了imported it

当尝试在应用程序中引用我的数据库时,会出现一个error

有什么办法解决这个问题吗?代码如下:

代码语言:javascript
复制
import UIKit 

import Firebase


class TableViewController: UITableViewController  {


    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        post()

        }

    func post(){


        let title = "Title"
        let message = "Message"

        let post : [String : AnyObject] = ["title" : title as AnyObject,
                                           "message" : message as AnyObject]

        let databaseRef = FirebaseApp.database().reference()

        databaseRef.child("Posts").childByAutoId().setValue(post)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()

        // Dispose of any resources that can be recreated.
    }


}
EN

Stack Overflow用户

发布于 2018-02-25 10:18:11

如果你的Firebase/Database版本是4.9.0,下面的代码会给你一个好的开始。

代码语言:javascript
复制
import UIKit
import Firebase

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

    override init() {
        super.init()
        FirebaseApp.configure()
    }

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        return true
    }
}

import UIKit
import FirebaseDatabase

class TableViewController: UITableViewController {
    // MARK: - Instance variables
    var databaseRef: DatabaseReference!

    // MARK: - Life cycle
    override func viewDidLoad() {
        super.viewDidLoad()

        //getting a reference to the node artists
        databaseRef = Database.database().reference()
    }
}
票数 1
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48968355

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档