Cannot Import Firebase Into Swift Class
Solution 1
There are two ways to install Firebase: manually, and with CocoaPods.
I recommend using CocoaPods. In your Podfile
, make sure you specify use_frameworks!
:
platform :ios, "9.0"
use_frameworks!
target 'MyProject' do
pod 'Firebase'
end
Then after you pod install
and open the MyProject.xcworkspace
, you should be able to use import Firebase
.
edit by Jay:
If you are targeting OS X your pod file may look more like this
platform :osx, '10.10'
use_frameworks!
target 'MyProject' do
pod 'FirebaseOSX', '>= 2.4.2'
end
Solution 2
For me it was this:
The Framework is called FirebaseAnalytics now and not Firebase.
The official documentation even has this wrong.
So after installing with CocoaPods (Firebase version 3.4.0) this works:
import FirebaseAnalytics
Solution 3
If you imported Firebase manually, update Framework Search Paths
and Header Search Paths
under your target's Build Settings
so they include the Firebase frameworks.
Solution 4
When using the CocoaPods installation method, you can start by removing the project workspace file:
rm -rf MyProject.xcworkspace
Then, edit the Podfile to following, which will be automatically set for the latest version of Firebase:
use_frameworks!
target 'MyProject' do
pod 'Firebase/Core'
pod 'Firebase/Database'
end
target 'MyProjectUITests' do
pod 'Firebase/Core'
pod 'Firebase/Database'
end
Finally, reinstall the pod
pod install
Solution 5
If you have added the firebase framework manually, delete it and add it again.Rebuild the project and it will work.
There seems to be a bug.This happens when you discard the changes.
Will Jackson
Updated on July 03, 2020Comments
-
Will Jackson almost 4 years
I am totally new to Firebase and building iOS apps. In Xcode 7, I am trying to import Firebase into my Swift class. In a swift file, I have typed "import Firebase".
I am getting an error that says
"No such module 'Firebase'"
Any help would be greatly appreciated.
-
Will Jackson over 8 yearsI am still having trouble. I tried using your Podfile and I still cannot use
import Firebase
. -
David East over 8 yearsCan you post your Podfile?
-
Will Jackson over 8 yearsHere is my Podfile:
platform :ios, '9.0' use_frameworks! target 'The Lighthouse App 1' do pod 'Firebase', '>= 2.4.2' end
-
X.Creates about 8 yearsBuilding project solves the issue after reinstalling with new podfile.
-
Glenn Posadas about 8 yearsLI Xinyang - I never thought of that! Damn. Thanks!
-
Rabimba Karanjai over 7 yearsThanks. This did solve it for me. I was following the official one and that just wanted me to import Firebase. Upvoted
-
Joel about 7 yearsIt depends on which sub-framework you are importing. If you are using the database, it is called import Firebase
-
chipbk10 over 6 yearsThanks for the configuration in OSX. However, I don't know how to do the configuration in code. In iOS, we do "FirebaseApp.configure()", but not in OSX.
-
Tomasz Nazarenko about 6 yearsI had to add to
Header search Paths
the path to the place where Firebase.h is. For example$(PROJECT_DIR)/Frameworks/Firebase
-
Droid Chris about 6 yearsThis worked for me. Added pods to stage and test targets.
-
Peter Zhao almost 6 yearsFor the newest Firebase,
import FirebaseCore
-
Alan Silva over 4 yearsI found the problem. I declared the pod 'Firebase' under the Tests Target... That might be the problem for others.
-
Ever Uribe almost 4 yearsYup can confirm it was import FirebaseCore if using the MacOS pods