无法将 Firebase 导入 Swift Class

Cannot Import Firebase Into Swift Class

我对 Firebase 和构建 iOS 应用程序完全陌生。在 Xcode 7 中,我正在尝试将 Firebase 导入我的 Swift class。在 swift 文件中,我输入了 "import Firebase"。

我收到一条错误消息

"No such module 'Firebase'"

如有任何帮助,我们将不胜感激。

有两种安装 Firebase 的方法:手动和使用 CocoaPods。

我推荐使用 CocoaPods。在您的 Podfile 中,确保指定 use_frameworks!:

platform :ios, "9.0"
use_frameworks!

target 'MyProject' do
 pod 'Firebase'
end

然后在你pod install打开MyProject.xcworkspace后,你应该可以使用import Firebase

周杰伦编辑:

如果您的目标是 OS X,您的 pod 文件可能看起来更像这样

platform :osx, '10.10'
use_frameworks!

target 'MyProject' do
  pod 'FirebaseOSX', '>= 2.4.2'
end

如果您手动添加了 firebase 框架,请将其删除并添加到 again.Rebuild 项目中,它将起作用。

当您放弃更改时,似乎会发生 bug.This。

使用CocoaPods安装方式时,可以从删除项目工作区文件开始:
rm -rf MyProject.xcworkspace

然后,将 Podfile 编辑为以下内容,它将自动设置为最新版本的 Firebase:

use_frameworks! 
target 'MyProject' do
  pod 'Firebase/Core'
  pod 'Firebase/Database'
end

target 'MyProjectUITests' do
  pod 'Firebase/Core'
  pod 'Firebase/Database'
end

最后,重新安装pod

pod install

对我来说,我必须确保 cocoapods 已更新到版本 1.0.0。

只是 运行 sudo gem install cocoapods,然后清理项目和 pod install。编译器应该不会再抱怨了。

对于我来说,我发现我在 pod 文件的错误行中写了 : (pod 'Firebase') 行。你只需要找到评论:# Pods for projectName 然后用 pods 替换它,例如:pod 'Firebase' 或:pod 'Firebase/Auth'

对我来说是这样的:

该框架现在称为 FirebaseAnalytics 而不是 Firebase。

官方文档竟然有这个错误。

因此,在使用 CocoaPods(Firebase 版本 3.4.0)安装后,这有效:

import FirebaseAnalytics

如果您手动导入 Firebase,请更新目标 Build Settings 下的 Framework Search PathsHeader Search Paths,以便它们包含 Firebase 框架。

  1. 打开终端并输入 cd "drag and drop your project" 回车
  2. 输入"pod init"
  3. 使用 xcode 打开 pod 文件
  4. 在use_frameworks之下!类型 吊舱 'Firebase' 吊舱 'Firebase/xxx'
  5. 返回终端并输入 "pod install" 6.open 您的项目文件夹和 运行 xxx.xcworkspace

在你的 Podfile 中确保除了你的 pod 'Firebase/Core' 之外还有 pod 'Firebase' 之后,:wq from vim and 运行 a命令 pod update。确保打开 .xcworkspace

所以在花了几个小时试图修复这个错误之后,我做了以下事情,我的生活恢复了正常

a) 转到我的 Podfile 并将 pod 'Firebase', '~> 4.8' 更改为 pod 'Firebase/Core'

b) 然后我进入我的 AppDdelegate 从 import Firebase 更改为 import FirebaseCore

如果您遇到与我相同的问题,此解决方案将适用于您

欢迎正在使用swift 3的朋友试用。它对我有用。

我的播客文件:

platform :osx, '9.0'
use_frameworks!

target 'MyProject' do
  pod 'Firebase/Messaging'
  pod 'Firebase'
end

A​​ppDelegate:

import FirebaseCore
import FirebaseMessaging