4

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?

user14492
  • 2,116
  • 3
  • 25
  • 44

5 Answers5

3

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

Reid
  • 734
  • 8
  • 15
1

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.

Michael Welch
  • 1,754
  • 2
  • 19
  • 32
  • Nope, never got it work... I just gave up. I am sure I had all the files included in the framework, because I [downloaded it](http://www.swifttoolbox.io), and the framework was woking fine in a .swift file. Now when I create a Playground in a workspace, I can see a Source folder in it, and a SupportCode.swift. I can copy file/code there if I need it (it is still unpredictable, I guess only simple functions work). Still would be nice if you could import Frameworks as it says on the Apple Developer website. Hopefully making Swift 2.0 open source will help. – user14492 Jul 24 '15 at 19:12
  • 1
    Which framework from the swift toolbox are you trying to use? Since I now have figured out how to do this, I'm interested in seeing if I'd have problems consuming whatever framework you are trying to consume. – Michael Welch Jul 25 '15 at 17:39
  • I'm trying to use [JSONJoy](https://github.com/daltoniam/JSONJoy-Swift) framework. – user14492 Jul 26 '15 at 19:00
  • Well, I can't get any of the "products" to build. I mean the compilation succeeds, but if I look in the Product folder all the targets are red. Which I think means they don't exist. When I finally got my framework testing in a Playground, the target name was black. – Michael Welch Jul 26 '15 at 22:00
  • 2
    You have to change the build scheme for OS X, then it'll build the framework, in the build folder. You can also change scheme for iOS Device (not the simulator) then it'll also build it. If you still have trouble, you can download it [here](https://www.dropbox.com/sh/iziz3zb2wpgkcyg/AAD9GVauCn10QRAyJdgqpc5Qa?dl=0). – user14492 Jul 27 '15 at 15:59
  • Yeah, I tried building all the schemes (iOS and OS X) and even a new scheme for a new target I added. None of them every turned color from red to black even though they all compile. I went back and looked at one of my own frameworks to see what the difference was, but couldn't isolate what was causing the problem. – Michael Welch Jul 27 '15 at 17:20
  • Yeah, I can't figure out a way to make it build in the path it says. It's a bug or something; I have another question [here](http://stackoverflow.com/questions/29360517/xcode-change-framework-s-path) just about that. Nonetheless the framework should build according to your Location Preferences (Preferences > Locations). Mine build in /ProjectDir/build/Debug/JSONJoy.framework – user14492 Jul 29 '15 at 16:13
  • Yep, the problem being if the names don't turn "black" then the Playground can't see them. In my own workspace with my test frameworks, that's how I finally got it to work. Once I saw the framework names go from red to black they were available in the playground. – Michael Welch Jul 29 '15 at 19:17
1

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).
Bob Stern
  • 23
  • 4
Yaroslav Y.
  • 327
  • 3
  • 11
1

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"

Kaccie Li
  • 126
  • 1
  • 5
0

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

Community
  • 1
  • 1
user14492
  • 2,116
  • 3
  • 25
  • 44