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
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).
It sometimes happens with cocoapods. Try following steps
Clean your build –
Command + K
Delete Derived data ->
Command + . -> Locations -> Derived data -> Delete all the sub folders.
Now quit your Xcode and reopen it.
go to the firebase.h file and check this line
#import <FirebaseCore/FirebaseCore.h>
Solution 1:
This solution works for me
I have imported before
import Firebase
but after update the pods. Additionally I have to import one moreimport FirebaseAnalytics
So if you need both
import Firebase
&import FirebaseAnalytics
then keep both otherwise for Events only requireimport FirebaseAnalytics
Solution 2:
pod 'Firebase/Analytics'
,pod 'Firebase/Crashlytics'
pod 'FirebaseAnalytics'
,pod 'FirebaseCrashlytics'
(Install pod with new pod name)import FirebaseCore
,import FirebaseAnalytics
instead justimport Firebase
opening "xcworkspace" file in xcode instead of "xcodeproj" solved my issue.
more info
It seems quite a bit depends on the broader picture of your setup. What versions are you using for:
I ran into this same issue earlier this week, and my setup was the following:
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…put the above in
AppDelegate.swift
and runFirebaseApp.configure()
in this methodDidn’t work.
As an experiment, I tried having
FirebasePerformace
,FirebaseAnalytics
, andFirebaseCrashlytics
code all over my app, but didn’t runFirebase.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
import
ed. Theimport 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.I put the above line of code in my
AppDelegate.swift
file in addition toimport 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.
Import these two framework in appDelegate and it should work.
import Firebase
import FirebaseFirestore
You need to import FirebaseCore instead of Firebase