iOS 9.2
斯威夫特 2.1.1
Xcode 7.2.1
Mac OSX 10.10.5
同样的错误在这里使用以下代码:
AppDelegate.swift:
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
FIRApp.configure()
return true
}
ViewController.swift:
import UIKit
import Firebase
class ViewController: UIViewController {
var db = FIRDatabase.database().reference()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//Create some data in Firebase db:
db.child("key").child("subkey").setValue("hello world")
}
我还将文件GoogleService-Info.plist 添加到我的项目目录中,如Firebase Getting Started Guide 中所述。
我使用以下 Rules 公开了我的 Firebase 数据库:
{
"rules": {
".read": true,
".write": true
}
}
对 ViewController.swift 进行以下更改对我有用:
class ViewController: UIViewController {
var db: FIRDatabaseReference!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
db = FIRDatabase.database().reference()
db.child("key").child("subkey").setValue("hello world")
}
在运行我的应用之前,我的 Firebase 数据库如下所示:
myiosdata-abc123: null
运行我的应用后,我的 Firebase 数据库如下所示:
myiosdata-abc123
- key
|
+--- subkey: “hello world”