How to use Swift Package Manager in Playground

六月ゝ 毕业季﹏ 提交于 2020-08-01 09:29:12

问题


Is it possible to use Swift Package Manager inside Xcode Playground ?


回答1:


It is not possible to use the Swift Package Manager in a playground at this time. The reason for that is that the Swift Package Manager is primarily used outside of apple platforms.

Apple mentions this on the Swift Package Manager's GitHub:

Note that at this time the Package Manager has no support for iOS, watchOS, or tvOS platforms

The Swift Package Manager is especially useful for writing Swift for platforms such as Linux and Mac. Uses may include creating servers based written in Swift or writing programs that can be run without a user interface (think home automations and IoT). It is a great way to organize packages without using Pods or other third-party setups. When you build the code for production (or debugging) it will download and incorporate packages into the project.

Note: This may change in the future, but is current as of Swift 3




回答2:


In Xcode 12, you can use Swift Packages with Xcode Playgrounds.

Steps to setup a workspace with a Swift Package and a Playground:

  • Open Xcode
  • Create a new Workspace (File > New > Workspace...)
  • Add the desired Swift package via File > Add Files to "Workspace Name"... selecting the package directory.
  • Create a new Playground via File > New > Playground.... Ensure that you select the Workspace we just created as the "Add to" and "Group" option during Playground creation (in the assistant where you select the Playground's location on disk).
  • You can now import the Package target into your Playground and starting exploring the Package's functionality.

You can find additional details and a sample project in this WWDC20 session: Explore Packages and Projects with Xcode Playgrounds

Ensure to check the new "Build active scheme" checkbox in the inspector for your existing Playgrounds.



来源:https://stackoverflow.com/questions/42736864/how-to-use-swift-package-manager-in-playground

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!