PlaygroundSupport no longer available for Playground apps

In Swift Playground 4.6.2 the package PlaygroundSupport is no longer available to Playground apps. The following test previously permitted apps run in the Playground vs compiled in XCode to support different behavior:

#if canImport(PlaygroundSupport)
        container = NSPersistentContainer(name: "myApp", managedObjectModel: Self.createModel())
#else
        container = NSPersistentCloudKitContainer(name: "myApp")
#endif

Since Swift Playground 4.6.2 the PlaygroundSupport package is no longer available for app projects in Playgrounds.

Is there a different compile type test which can be used to differentiate compilation for Swift Playground apps ?

I am currently having to use a runtime workaround (below) but would prefer a compile time test is an alternative is available.

    public static var inPlayground: Bool {
        if Bundle.allBundles.contains(where: { ($0.bundleIdentifier ?? "").contains("swift-playgrounds") }) {
            return true
        } else {
            return false
        }
    }

Since Swift Playground 4.6, as you have observed, it is no longer possible to import PlaygroundSupport because the PlaygroundSupport framework provides no functionality to app playgrounds.

However, starting in Swift Playground 4.6, you can conditionalize code with the SwiftPlaygrounds condition:

#if SwiftPlaygrounds
    container = NSPersistentContainer(name: "myApp", managedObjectModel: Self.createModel())
#else
    container = NSPersistentCloudKitContainer(name: "myApp")
#endif
PlaygroundSupport no longer available for Playground apps
 
 
Q