insys
insys

Reputation: 1288

Importing 3rd party framework in a Playground's "SupportCode.swift"

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.

Upvotes: 6

Views: 1278

Answers (4)

nikhilgohil11
nikhilgohil11

Reputation: 1225

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

Upvotes: 0

Aasveen Kaur
Aasveen Kaur

Reputation: 21

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.

Upvotes: 1

Edison
Edison

Reputation: 11987

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.

Upvotes: 0

iluvcapra
iluvcapra

Reputation: 9464

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.

Upvotes: 0

Related Questions