skip to Main Content

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
  }

8

Answers


  1. 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).

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
  3. go to the firebase.h file and check this line #import <FirebaseCore/FirebaseCore.h>

    Login or Signup to reply.
  4. 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
    Login or Signup to reply.
  5. opening "xcworkspace" file in xcode instead of "xcodeproj" solved my issue.

    more info

    Login or Signup to reply.
  6. 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.

    Login or Signup to reply.
  7. Import these two framework in appDelegate and it should work.

    import Firebase

    import FirebaseFirestore

    Login or Signup to reply.
  8. You need to import FirebaseCore instead of Firebase

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search