

In Xcode 12.5, this generated a warning in the playground console (edited for brevity): What happens if I try to access the GridView directly? The app target has the Shared package as a dependency but I still need to import the package to the playground for it to be in scope: This has no effect on my playground accessing a view controller. I’ve taken my GridView class and moved it to a Shared swift package: Let’s try using this with a more realistic project where I’m using some Swift packages. You can turn this on for playgrounds created with earlier versions of Xcode in the playground settings: Starting with Xcode 12.5, new playgrounds have access to the application target by default.

This works not just for types (classes, structs, enums, etc.) but also for resources in the app target asset catalog: We can now try accessing the view controller in our app target: Xcode complains about “Workspace integrity”:Ĭlosing and reopening the Xcode project fixes the problem: I also don’t see the Sources and Resources sub-folders of the playground: The playground does not show up in the editor. Clicking on the playground in the navigator does nothing. Name the playground and save it in the root of the project directory and add it to the top level project group:Īt this point I hit a problem (FB8996491). I’m using that view in a view controller I’ve named GridController:Īdd a blank iOS playground to the project in the usual way ( File > New > Playground.): It has a small custom view, named GridView, that draws a grid.

Let’s give it a try with my minimal Xcode project. To enable this functionality in existing playground documents, turn on the Import App Types option in the File Inspector. New playgrounds you create have this option on by default. From the Xcode 12.5 release notes:Ī Playground in an app’s project can now access symbols from the app target. Xcode 12.5 has enhanced playground support that, if it works, might finally give me what I want. That works well but only for types and resources you put in the package.
#Xcode 12.5 release notes code#
With the release of Xcode 11, I switched to sharing code by creating Swift packages. My first try at adding playgrounds to Xcode projects added shared code to a framework that I then imported into the playground. The problem has always been that a playground added to a project did not automatically have access to the types in the project. I’ve long wanted to have a scratch playground attached to an Xcode project that I could use to try out ideas and play with the types in the project. This means you are not forced to import frameworks or Swift packages to share code between your app target and the playground. When you add a new playground to a project it defaults to having access to the types in your App target. Xcode 12.5 added enhanced playground support.
