Cannot Import Firebase Into Swift Class

34,898

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.

Share:
34,898
Will Jackson
Author by

Will Jackson

Updated on July 03, 2020

Comments

  • Will Jackson
    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
    Will Jackson over 8 years
    I am still having trouble. I tried using your Podfile and I still cannot use import Firebase.
  • David East
    David East over 8 years
    Can you post your Podfile?
  • Will Jackson
    Will Jackson over 8 years
    Here is my Podfile: platform :ios, '9.0' use_frameworks! target 'The Lighthouse App 1' do pod 'Firebase', '>= 2.4.2' end
  • X.Creates
    X.Creates about 8 years
    Building project solves the issue after reinstalling with new podfile.
  • Glenn Posadas
    Glenn Posadas about 8 years
    LI Xinyang - I never thought of that! Damn. Thanks!
  • Rabimba Karanjai
    Rabimba Karanjai over 7 years
    Thanks. This did solve it for me. I was following the official one and that just wanted me to import Firebase. Upvoted
  • Joel
    Joel about 7 years
    It depends on which sub-framework you are importing. If you are using the database, it is called import Firebase
  • chipbk10
    chipbk10 over 6 years
    Thanks 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
    Tomasz Nazarenko about 6 years
    I had to add to Header search Paths the path to the place where Firebase.h is. For example $(PROJECT_DIR)/Frameworks/Firebase
  • Droid Chris
    Droid Chris about 6 years
    This worked for me. Added pods to stage and test targets.
  • Peter Zhao
    Peter Zhao almost 6 years
    For the newest Firebase, import FirebaseCore
  • Alan Silva
    Alan Silva over 4 years
    I found the problem. I declared the pod 'Firebase' under the Tests Target... That might be the problem for others.
  • Ever Uribe
    Ever Uribe almost 4 years
    Yup can confirm it was import FirebaseCore if using the MacOS pods