[Bug] SWIFT_PACKAGE not defined in iPad Playgrounds 4

In the new Swift Playground App format, we can share code between an iPad's Playground and Mac's Xcode. But some key behaviors are inconsistent.

For example, using Xcode/iPad Playground to new a Test "Swift Playground App" and adding the following code.

We'll see "1" on Xcode while "2" on iPad Playground App

Test.swiftpm

struct ContentView: View {
  var body: some View {
    #if SWIFT_PACKAGE
    Text("1") // Using Xcode to open
    #else
    Text("2") // Using iPad Playground App to open
    #endif
  }
}

I think for a Swift Playground App, they should both to be "1"

Answered by KyleYe in 704571022

Current we could workaround by using a custom define in Package.swift

swiftSettings: [.define("SWIFT_PACKAGE")])
Accepted Answer

Current we could workaround by using a custom define in Package.swift

swiftSettings: [.define("SWIFT_PACKAGE")])
[Bug] SWIFT_PACKAGE not defined in iPad Playgrounds 4
 
 
Q