在Playground的“SupportCode.swift”中导入第三方框架

时间:2023-01-23 21:09:16

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

有没有办法在PlayC的Sources目录中的“SupportCode.swift”文件中包含一个(非Apple)框架?

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.

当导入指令放在Playground本身时成功导入框架,当我尝试在SupportCode.swift中导入相同的框架时,我会弹出“No such module”错误。

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

我将我的游乐场嵌入工作场所,并添加了所需的框架。

4 个解决方案

#1


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"

这是一个黑客。如果您有像“Parse.framework”这样的文件,只需将其复制到Xcode的系统框架文件夹“/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/构架”

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

现在,您可以像在任何其他系统框架中一样在操场中导入此框架。

#2


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.

为了导入外部框架,您必须在Xcode工作区中拥有操场和框架的目标/项目。一旦你拥有了它并构建了框架,你就可以通过导入导入框架。

#3


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.

您还可以将Finder中的框架项目拖动到工作区中的项目导航器中。

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

在编辑器中打开playground文件,并使用import语句添加导入自定义框架。

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.

    如果它是iOS框架,则它是为64位运行时目标而构建的。

  • 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.

    如果它是Objective-C框架,则将“定义模块”构建设置设置为“是”。

#4


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://*.com/a/47922876/855261

请不要错过在您的项目中添加空的.swift文件,如此答案中所述https://*.com/a/47922876/855261

#1


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"

这是一个黑客。如果您有像“Parse.framework”这样的文件,只需将其复制到Xcode的系统框架文件夹“/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/构架”

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

现在,您可以像在任何其他系统框架中一样在操场中导入此框架。

#2


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.

为了导入外部框架,您必须在Xcode工作区中拥有操场和框架的目标/项目。一旦你拥有了它并构建了框架,你就可以通过导入导入框架。

#3


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.

您还可以将Finder中的框架项目拖动到工作区中的项目导航器中。

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

在编辑器中打开playground文件,并使用import语句添加导入自定义框架。

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.

    如果它是iOS框架,则它是为64位运行时目标而构建的。

  • 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.

    如果它是Objective-C框架,则将“定义模块”构建设置设置为“是”。

#4


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://*.com/a/47922876/855261

请不要错过在您的项目中添加空的.swift文件,如此答案中所述https://*.com/a/47922876/855261