Use of unresolved identifier 'FIRDatabase'

2020-07-02 08:35发布

问题:

Xcode tells me that FIRDatabaseis not an identifier. My code:

import UIKit
import Firebase

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        FIRApp.configure()
        FIRDatabase.database().persistenceEnabled = true // Use of unresolved identifier 'FIRDatabase'
        return true
    }
}

I am using:

Xcode 7.2.1, Firebase 3.0.2, OSX 10.10.5

Podfile content:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

target 'myapp' do
pod 'IQKeyboardManagerSwift', '<= 4.0.0'
pod 'JSQMessagesViewController', '<= 7.3.1'
pod 'Firebase'
end

回答1:

You need to add

  pod 'Firebase/Database'

to your pod file as explained here

https://firebase.google.com/docs/database/ios/start

Here you can find which pod includes which feature Pods and Features



回答2:

What worked for me, in addition to adding pod 'Firebase/Database', was (which is missing from the current docs):

import FirebaseDatabase

Tested with Xcode 7.3.1, CocoaPods 0.39.0 & 1.0.1 on macOS 10.11.5. To make sure you're doing this correctly, please make sure your Podfile.lock looks something like:

PODS:
  ...
  - FirebaseDatabase (3.0.1):
    - FirebaseAnalytics (~> 3.2)
  ...

P.S. I ran into CocoaPods issues that forced me to delete the derived data folder, so try that as well.



回答3:

New syntax for using FIRDatabase:

Database.database().reference()


回答4:

This worked for me

  1. Add pod 'Firebase/Database' to your pod file
  2. pod install
  3. Open XCode and Rebuild Project


回答5:

  1. First Just make sure your pod file contains pod 'Firebase/Database'
  2. Add those two lines to your code:

import Firebase

import FirebaseDatabase



回答6:

  1. add pod 'Firebase/Database' to your pod file
  2. run the pod update command from your project dir
  3. import

    `*import Firebase

    import FirebaseDatabase*`

  4. Initialize and Configure your Firebase

    `*var ref: DatabaseReference!

    ref = Database.database().reference()*`