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
}
}