9

I am having a issue. Please Help. Whenever I try to run this code it has an error and says Cannot find 'FirebaseApp' in scope. Please Help!!!

import UIKit
import Firebase

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

  var window: UIWindow?

  func application(_ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions:
      [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    FirebaseApp.configure()
    return true
  }
user14963385
  • 141
  • 1
  • 1
  • 6

8 Answers8

16

Solution 1:

enter image description here This solution works for me

I have imported before import Firebase but after update the pods. Additionally I have to import one more import FirebaseAnalytics

So if you need both import Firebase & import FirebaseAnalytics then keep both otherwise for Events only require import FirebaseAnalytics

Solution 2:

  • Problem with older pod names - pod 'Firebase/Analytics', pod 'Firebase/Crashlytics' enter image description here
  • Use new pod name to integrate pod 'FirebaseAnalytics', pod 'FirebaseCrashlytics' (Install pod with new pod name)
  • Import import FirebaseCore, import FirebaseAnalytics instead just import Firebase enter image description here
Ashvin
  • 8,227
  • 3
  • 36
  • 53
8

It sometimes happens with cocoapods. Try following steps

  1. Clean your build -Command + K

  2. Delete Derived data -> Command + . -> Locations -> Derived data -> Delete all the sub folders.

  3. Now quit your Xcode and reopen it.

Somesh Karthik
  • 498
  • 4
  • 7
7

opening "xcworkspace" file in xcode instead of "xcodeproj" solved my issue.

more info

2

It seems quite a bit depends on the broader picture of your setup. What versions are you using for:

  • Xcode?
  • Swift?
  • CocoaPods?
  • Firebase?
  • Xcode Project Format?
  • maybe others?

I ran into this same issue earlier this week, and my setup was the following:

  • Xcode 13.3
  • Swift 5
  • CocoaPods 1.11.3
  • Firebase/Analytics (8.12.1)
  • Firebase/Core (8.12.1)
  • Firebase/Crashlytics (8.12.1)
  • FirebasePerformance (8.12.0)
  • Xcode Project Format 3.2-compatible

When I went to build (for sim or device, didn't matter) I was getting Cannot find 'FirebaseApp' in scope as an error. I literally did what Google says to do: https://firebase.google.com/docs/database/ios/start#set_up

import Firebase

...put the above in AppDelegate.swift and run FirebaseApp.configure() in this method

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool

Didn't work.

As an experiment, I tried having FirebasePerformace, FirebaseAnalytics, and FirebaseCrashlytics code all over my app, but didn't run Firebase.configure() in the app delegate.

It compiled and ran!... but crashed when the app encountered some metrics capturing code from one of the above Firebase modules. So, clearly, the pod install worked and is fine... So it wasn't a CocoaPods issue for me.

It then seemed to me that something was awry with what was being imported. The import Firebase statement alone (as they claim) wasn't doing what it was supposed to do.

So, what did I try? Well, having used Firebase in the past, at one point, Google recommended using import FirebaseCore. So that's what I did.

import FirebaseCore

I put the above line of code in my AppDelegate.swift file in addition to import Firebase, and problem solved! It now builds and runs on sim and device.

I would also recommend looking into what @AshvinA and @SomeshKarthik did if you are using features for those specific modules under the Firebase paradigm.

Again, your solution maybe different depending on the version(s) of various aspects of your project setup.

Jacob M. Barnard
  • 1,347
  • 1
  • 10
  • 24
0

I cannot comment on the post for some reason, but I think I know the answer. You need to download cocoapods and install the pods for Firebase. Take a look at this link and you will see what I mean: https://firebase.google.com/docs/ios/setup

Feel free to leave a comment if you need clarification.

Edit: looked at the page, it forgot to include the command "sudo gem install cocoapods" if you don't have cocoapods installed already. Also, if you are on a Mac that is not up to Big Sur, you need to manually update ruby. Just try to find RVM (ruby version manager). I had to do it 3 times already, but I forget how to do it (its a repressed memory).

FrankDad
  • 23
  • 7
  • Hi, Thanks so much but I have already installed the pods – user14963385 Apr 16 '21 at 04:50
  • pod 'Firebase/ABTesting' pod 'Firebase/Auth' # Limited watchOS support pod 'Firebase/Crashlytics' pod 'Firebase/Database' # No watchOS support yet pod 'Firebase/Firestore' # No watchOS support yet pod 'Firebase/Functions' # No watchOS support yet pod 'Firebase/Messaging' pod 'Firebase/Performance' # No macOS, tvOS, watchOS, and Catalyst support yet pod 'Firebase/RemoteConfig' pod 'Firebase/Storage' pod 'Firebase/Analytics' pod 'Firebase' pod 'Firebase/AppDistribution' pod 'Firebase/RemoteConfig' – user14963385 Apr 16 '21 at 04:50
  • have you installed cocoapods yet? – FrankDad Apr 16 '21 at 04:52
  • I installed cocoapods and I have MacOS Big Sur, but it is still not working. – user14963385 Apr 16 '21 at 04:53
  • have you ran "pod install" yet? If not, do that, if you had, run "pod update". you would do this in the terminal were the project is living. If you have done both of these things and it isn't working, you may have to de-intergrate the pods. – FrankDad Apr 16 '21 at 04:59
  • 1
    I just updated the pods, but I am still getting the error. – user14963385 Apr 16 '21 at 05:17
  • Then try following this: https://github.com/CocoaPods/cocoapods-deintegrate – FrankDad Apr 16 '21 at 06:05
0

Import these two framework in appDelegate and it should work.

import Firebase

import FirebaseFirestore

0

You need to import FirebaseCore instead of Firebase

Yevhenii
  • 1
  • 1
-1

go to the firebase.h file and check this line #import <FirebaseCore/FirebaseCore.h>