Unable to import Firebase into Swift Playground

前端 未结 2 788
名媛妹妹
名媛妹妹 2021-01-25 03:42

hope this finds you well.

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,

相关标签:
2条回答
  • 2021-01-25 04:05

    (Breaking out from a comment to an answer)

    I was able to get around this in two ways. The first thing may be enough, but if not the second should do it.

    1. Compile the workspace. Although the Pods are in the project, the frameworks don't fully exist yet. Compiling may be enough to trigger things.

    If that doesn't work...

    1. As you mentioned originally in your question, create a new Framework and add Firebase/Firestore as a dependency. My Podfile ended up looking like:
    target 'FirebasePlaygroundDemo' do
      use_frameworks!
      pod 'Firebase/Firestore'
    end
    
    target 'FirebaseDummy' do
      use_frameworks!
      pod 'Firebase/Firestore'
    end
    

    where FirebaseDummy was the name of my newly created Framework. Then, in the Playground I had to import FirebaseDummy as well as FirebaseCore and FirebaseFirestore.

    Hope that helps, can assist further if not!

    0 讨论(0)
  • 2021-01-25 04:14

    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. 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!
    

    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!

    0 讨论(0)
提交回复
热议问题