How to use a custom framework with a playground in

2020-07-11 07:44发布

问题:

I am trying to use a custom framework in a playground as described in this Apple documentation:

http://help.apple.com/xcode/mac/9.0/#/devc9b33111c

However, I am unable to get the playground to recognize the framework (https://github.com/gk-brown/MarkupKit). It is a 64-bit Objective-C framework that defines a module.

Here is what I have tried:

  • Create a new "single view" playground
  • As directed in the document, open the playground and choose File > Save As Workspace
  • Close the playground
  • Open the workspace containing the playground
  • Attempt to choose File > Add Files to [Workspace Name]

The menu item is actually named "Add Files..." and is disabled. I'm able to work around this by opening the Navigator panel and selecting Project Navigator. The menu item changes to "Add Files to TestPlayground" and becomes enabled.

Moving on, as directed in the document:

  • Navigate to the directory containing the framework, select the framework, and click "Add"
  • In the editor, open the desired playground source file
  • Add an import statement for the framework (e.g. "import MarkupKit")

The console displays the following error:

error: TestPlayground.playground:5:8: error: no such module 'MarkupKit'

The document additionally notes that the workspace must contain at least one active scheme that builds a target. However, adding a project to the workspace and building it does not resolve the problem. The playground is still unable to see the framework.

Based on what I've read elsewhere on SO, it seems like this should be possible. However, most of the information I have found is 2-3 years old and may be out of date. The framework is a universal binary, and I have tried trimming it using lipo as suggested in some other posts. Specifically, I did this:

https://github.com/gk-brown/MarkupKit/wiki/Deployment

Unfortunately, it didn't help.

Any suggestions would be very much appreciated.

回答1:

You steps looks okay but Only missing part I see here is adding a .swift Empty file in the project.

This actually compiles below project so after this framework will be ready to import into the playground.