ios 无法将 Firebase 导入 Swift 类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34215522/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot Import Firebase Into Swift Class
提问by Will Hymanson
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".
我对 Firebase 和构建 iOS 应用程序完全陌生。在 Xcode 7 中,我试图将 Firebase 导入到我的 Swift 类中。在 swift 文件中,我输入了“import Firebase”。
I am getting an error that says
我收到一个错误,说
"No such module 'Firebase'"
“没有这样的模块‘Firebase’”
Any help would be greatly appreciated.
任何帮助将不胜感激。
采纳答案by David East
There are two ways to install Firebase: manually, and with CocoaPods.
有两种安装 Firebase 的方法:手动和使用 CocoaPods。
I recommend using CocoaPods. In your Podfile
, make sure you specify use_frameworks!
:
我推荐使用 CocoaPods。在您的 中Podfile
,请确保指定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
.
然后你pod install
打开后MyProject.xcworkspace
,你应该就可以使用了import Firebase
。
edit by Jay:
杰伊编辑:
If you are targeting OS X your pod file may look more like this
如果您的目标是 OS X,您的 pod 文件可能看起来更像这样
platform :osx, '10.10'
use_frameworks!
target 'MyProject' do
pod 'FirebaseOSX', '>= 2.4.2'
end
回答by Ole
For me it was this:
对我来说是这样的:
The Framework is called FirebaseAnalytics now and not Firebase.
该框架现在称为 FirebaseAnalytics 而不是 Firebase。
The official documentation even has this wrong.
官方文档甚至有这个错误。
So after installing with CocoaPods (Firebase version 3.4.0) this works:
因此,在使用 CocoaPods(Firebase 版本 3.4.0)安装后,这有效:
import FirebaseAnalytics
回答by Crashalot
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.
如果您手动导入 Firebase,请更新您的目标下的Framework Search Paths
和Header Search Paths
,Build Settings
以便它们包含 Firebase 框架。
回答by Idan
When using the CocoaPods installation method, you can start by removing the project workspace file:rm -rf MyProject.xcworkspace
使用 CocoaPods 安装方式时,可以先删除项目工作区文件:rm -rf MyProject.xcworkspace
Then, edit the Podfile to following, which will be automatically set for the latest version of Firebase:
然后,将 Podfile 编辑为以下内容,它将为最新版本的 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
pod install
回答by shivamkaushik
If you have added the firebase framework manually, delete it and add it again.Rebuild the project and it will work.
如果您手动添加了 firebase 框架,请将其删除并重新添加。重新构建项目,它将起作用。
There seems to be a bug.This happens when you discard the changes.
似乎存在错误。当您放弃更改时会发生这种情况。
回答by Habib Alejalil
- open terminal and type cd "drag and drop your project" Enter
- type "pod init"
- open pod file with xcode
- under use_frameworks! type pod 'Firebase' pod 'Firebase/xxx'
- back to terminal and type "pod install" 6.open your project folder and run xxx.xcworkspace
- 打开终端并输入cd“拖放你的项目”回车
- 输入“pod init”
- 用xcode打开pod文件
- 在 use_frameworks 下!输入 pod 'Firebase' pod 'Firebase/xxx'
- 回到终端并输入“pod install” 6.打开你的项目文件夹并运行 xxx.xcworkspace
回答by Guy Daher
For me, I had to make sure that cocoapods was updated to version 1.0.0.
对我来说,我必须确保将 cocoapods 更新到 1.0.0 版。
Just run sudo gem install cocoapods
, then clean project and pod install
. Compiler should not complain anymore.
只需运行sudo gem install cocoapods
,然后清理项目和pod install
. 编译器不应该再抱怨了。
回答by Vision Mkhabela
So after spending hours and hours trying to fix this error I did the following and my life went back to normal
所以在花了几个小时试图修复这个错误之后,我做了以下事情,我的生活恢复了正常
a) Went to my Podfile and changed pod 'Firebase', '~> 4.8'to pod 'Firebase/Core'
a) 转到我的 Podfile 并将 pod 'Firebase', '~> 4.8'更改为 pod 'Firebase/Core'
b) Then I went into my AppDdelegate changed from import Firebaseto import FirebaseCore
b)然后我进入了我的 AppDdelegate 从import Firebase更改为import FirebaseCore
If you were facing the same problem as me this solution will work for you
如果您遇到与我相同的问题,此解决方案对您有用
回答by Naval Hasan
Those who are using swift 3
are welcome to try this. It worked for me.
swift 3
欢迎正在使用的朋友们尝试一下。它对我有用。
My pod file:
我的豆荚文件:
platform :osx, '9.0'
use_frameworks!
target 'MyProject' do
pod 'Firebase/Messaging'
pod 'Firebase'
end
AppDelegate:
应用委托:
import FirebaseCore
import FirebaseMessaging
回答by ???? ???????
For me, I found that I wrote the line : (pod 'Firebase') in the wrong line in the pod file. you only need to find the comment : # Pods for projectName and then replace it with pods like: pod 'Firebase' or : pod 'Firebase/Auth'
对我来说,我发现我在 pod 文件的错误行中写了行 : (pod 'Firebase') 。您只需要找到评论:# Pods for projectName 然后将其替换为 pod,例如:pod 'Firebase' 或 : pod 'Firebase/Auth'