user14492
user14492

Reputation: 2234

Error importing framework in Playground

I’m following the instructions for Importing Custom Frameworks into Playground, but I still keep getting "No such module” error. I have tried adding everything in the workspace; a project with just Framework target, project of Cocoa Application with the framework, and just the Framework. I also tried creating a playground in the Application where I imported the framework, I can even import it in other swift file without any problem; but I can’t seem to be able to import it in playground.

Can someone please tell me what I might be doing wrong?

Upvotes: 5

Views: 2009

Answers (5)

Yaroslav Y.
Yaroslav Y.

Reputation: 357

I've spent for this more than 4 hours. But i've solved it for XCode 10.

You're unable to add any framework into the Playground if there's no target for it the Workspace where the Playground is. So as you using downloaded framework (so am i) — you're doomed to fail with it.

The workable manual could be found here (God bless this guy): https://www.pardel.dev/blog/3rd-party-frameworks-in-xcode-playgrounds

tldr: the easiest way is to:

  1. Download 3rd party framework sources.
  2. Open *.xcodeproj
  3. Add Playground to the Project.
  4. Build project for any iOS simulator by cmd+b (have no idea how to use any macOS frameworks yet).
  5. And it should work (at least it does for me).

Upvotes: 2

Kaccie Li
Kaccie Li

Reputation: 126

I would like to echo what Reid said:

Try building your framework target using a simulator! I had only built mine using the generic device which doesn't work for playgrounds!

If you've updated to Xcode 12, you also need to make the "Build Active Scheme" box is checked. Select your playground and go to the inspector. The checkbox will be under "Playground Settings"

Upvotes: 1

Reid
Reid

Reputation: 734

Try building your framework target using a simulator! I had only built mine using the generic device which doesn't work for playgrounds!

Upvotes: 3

user14492
user14492

Reputation: 2234

I solved my problem with a different solution than Michael Welch's. I had my Xcode derived data setting different than original. Go to Preferences > Locations > Derived Data > Advanced and select Unique. This solved the framework not appearing in playground problem for me.

Derived Data

Upvotes: 0

Michael Welch
Michael Welch

Reputation: 1784

Did you ever get it to work? I figured out my issue. The code I was trying to import wasn't in a Framework Target. I had to add a new target to my project of type Cocoa Framework. Then include my source files in that framework, and then finally build that target. Then it worked.

Upvotes: 1

Related Questions