无法将Firebase导入Swift Playground [英] Unable to import Firebase into Swift Playground

查看:74
本文介绍了无法将Firebase导入Swift Playground的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望这会让您感觉很好.

hope this finds you well.

在过去的数小时痛苦中,我一直在尝试找到一种将Firebase模块导入到我的工作区 FooWorkspace 中的Swift Playground的方法.在尝试将Firebase导入我的Playground之前,我已经尝试了以下方法:

For the past few painful hours, I've been trying to find a way to import the Firebase module into my Swift Playground, inside of my workspace, FooWorkspace. I've tried the following before subsequently importing Firebase in my Playground:

  1. 在我的两个项目 FooProject Pod 之外的 FooWorkspace 中离开操场,如中.
  2. 将我的游乐场留在我的 FooProject 中.
  1. Leaving the Playground in FooWorkspace, outside of both my projects FooProject and Pod, as shown here.
  2. Creating a Framework FooFramework and indicating in my Podfile to allocate the Firebase pods into FooFramework, and then importing FooFramework in my Playground, like in this.
  3. Leaving my Playground inside my FooProject instead.

但是,所有这些都不起作用.我目前正在使用cocoapods-1.8.4和XCode版本11.1(11A1027).

However, all these did not work one bit. I am currently using cocoapods-1.8.4 and XCode Version 11.1 (11A1027).

我也不确定一些要点.

There were a few points that i am unsure of as well.

  1. 我能够导入FirebaseCore,但是Playground中的自动补全功能无法正常工作,而且我通常无法像在项目中那样进行编码.
  2. 当我创建框架时,给出的选项不是可可触摸式框架,而是框架.

我确实是iOS开发的新手,并且在现实生活中没有人讨论此事,所以我觉得过去一天我一直在兜圈子.任何帮助都将不胜感激!

I am truly a novice at iOS development, and know no one in real-life to discuss this, so i feel like i've been going around in circles the past day. Any help at all is greatly appreciated!

编辑: 在收到@ryanwils的一些有用建议后,我完全重新启动了XCode,然后能够导入FirebaseCore/FirebaseFirestore.但是,从Firebase调用任何函数都会产生错误.例如,当我呼叫Firestore.firestore()时,它给了我

EDITS: After some helpful advice from @ryanwils, i restarted my XCode completely and was then able to import FirebaseCore/FirebaseFirestore. However, calling any function from Firebase produced an error. For example, when i called Firestore.firestore(), it gave me an error of

Couldn't lookup symbols: _OBJC_CLASS_$_FIRApp

Couldn't lookup symbols: _OBJC_CLASS_$_FIRApp

有人能指出我正确的方向吗?我已经四处搜寻,有些线程提到它看不到我的吊舱/班级,但是如果我确实能够将Firebase导入我的游乐场,那它不应该已经可以看到我的吊舱了吗?谢谢!

Can anyone point me in the right direction? I've googled around and some threads have mentioned that it is unable to see my pods/classes, but if i am actually able to import Firebase into my playground, shouldn't it be able to see my pods already? Thanks!

推荐答案

我非常感谢@ryanwils,终于找到了如何在操场上成功运行Firebase代码的方法.我们确实需要为此创建一个额外的框架.

With immense gratitude to @ryanwils, I've finally found out how to successfully run the Firebase code in a playground. We do need to create an additional framework for this to work.

这些是我在操场上成功运行代码所采取的步骤:

These are the steps I've taken to successfully do run code on the playground:

  1. 设置工作区,以使Playground文件与xcodeproj文件处于同一级别.
  2. 按照@ryanwils的说明,创建一个新框架,并在您的Podfile中指定新框架所需的Pod.我已将其命名为PlaygroundFramework,如您在下面的代码中所见.
  3. 在Playground文件的resources文件夹下,复制到GoogleService-Info.plist中,如下图所示:
  4. 在您的Playground中使用以下代码:
  1. Set up your workspace so that the Playground file is on the same level as your xcodeproj files.
  2. As per @ryanwils instructions, create a new framework and in your Podfile specify the required pods for the new framework. I've named mine PlaygroundFramework, as you'll see in the code later below.
  3. Under the resources folder of your Playground file, copy in your GoogleService-Info.plist, like in the photo shown below:
  4. Use the following code in your Playground:

import UIKit
import PlaygroundSupport
import PlaygroundFramework // Your new framework name here
import FirebaseCore
import FirebaseFirestore
// ... other modules you need. Remember to build first!

let filePath = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist")!
let options = FirebaseOptions(contentsOfFile: filePath)
FirebaseApp.configure(options: options!)

// Your Firebase queries will work here now!

上面的步骤也使我能够从我的podfile中的各个pod中运行代码.希望它适用于任何需要它的人,并再次感谢@ryanwils!

The steps above allowed me to run code from various pods in my podfile as well. Hope it works for whoever needs it, and thanks once again to @ryanwils!

这篇关于无法将Firebase导入Swift Playground的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆