6

Is there a way to include a (non-Apple) framework in the "SupportCode.swift" file, in the Sources directory of a Playground?

While the framework is successfully imported when the import directive is placed in the Playground itself, I get a "No such module" error popping up when trying to import the same framework in SupportCode.swift.

I have my playground embedded in a workplace with the required frameworks added to it as well.

2
  • I just hit the same problem. Ever find an answer?
    – Rob N
    Apr 25, 2015 at 17:43
  • Not really.. couldn't find anything online so I gave up after a while.
    – insys
    Apr 25, 2015 at 21:56

4 Answers 4

1

It is a hack. if you have file like "Parse.framework", just copy it to Xcode's system frameworks folder at "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks"

Now you can import this framework in playground just like any other system framework.

0

This didn't work until recently.

In order to import an external framework, you have to have the playground and your framework's target/project in an Xcode Workspace. Once you have that and you build the framework, you can just import the framework with an import.

2
  • Sorry for the late comment, but this still doesn't work as of Xcode 7.0.1. I have a workspace with an existing framework project, and try to add a playground to it. I can import the framework in the playground itself, but not to any swift source files in the Sources folder. I get no such module error.
    – insys
    Oct 19, 2015 at 9:58
  • Running into the same problem. Did you find a solution? Mar 16, 2016 at 13:55
0

If the playground is already in a project that is not a workspace file, you can convert the project to a workspace by choosing File > Save As Workspace then add the playground to that workspace.

You can also drag the framework project in the Finder to the project navigator in the workspace.

Open the playground file in the editor, and add import the custom framework using an import statement.

NOTE: These are the conditions.

  • The framework is in the same workspace as the playground.

  • The framework has already been built.

  • If it is an iOS framework, it is built for a 64-bit run-time destination.

  • The workspace contains at least one active scheme that builds a
    target.

  • If it is an Objective-C framework, it sets the Defines Module build
    setting to Yes.

1
  • Thanks for your reply. Please take a look at the comment I left above. In a nutshell, it still doesn't work afaik/tried. I made sure all conditions you describe are met.
    – insys
    Oct 19, 2015 at 10:01
0

I have found this tutorial exactly how I was doing in my project.

https://m.pardel.net/using-3rd-party-frameworks-in-swift-playgrounds-fd415f6dba10

Please don't miss to add empty .swift file in your project as describe in this answer https://stackoverflow.com/a/47922876/855261

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.