Unable to rename the Swift Playground or add an icon when package dependencies is imported

I'm unable to rename my Swift Playground or add/change the app icon when I imported a package dependency after upgraded my Swift Playgrounds App to the newest version. Every time I tried to do that, the whole project will be destroyed and showed error message below.

I wonder if anyone have same experience with me or someone can tell me the solution, it terrifies me and I'm worried that I'll be unable to submit my project on time because of that.

Answered by CMDdev in 824179022

I was able to reproduce the behavior you described, and I recommend you submit a bug via Feedback Assistant, and make sure to reply with the feedback's ID on this thread for reference. You may also link this thread on your feedback.

Some details about this bug

Swift Playgrounds are a superset of swiftpm (the Swift Package format), and they have a "Package.swift` settings file that you may access via clicking on "Show Package Contents" option in Finder:

This file includes all your App Playground's settings and used packages. Here's how it looks on a functional app, with the same package you were using:

// swift-tools-version: 5.9

// WARNING:
// This file is automatically generated.
// Do not edit it by hand because the contents will be replaced.

import PackageDescription
import AppleProductTypes

let package = Package(
    name: "My App",
    platforms: [
        .iOS("18.1")
    ],
    products: [
        .iOSApplication(
            name: "My App",
            targets: ["AppModule"],
            displayVersion: "1.0",
            bundleVersion: "1",
            appIcon: .placeholder(icon: .palette),
            accentColor: .presetColor(.purple),
            supportedDeviceFamilies: [
                .pad,
                .phone
            ],
            supportedInterfaceOrientations: [
                .portrait,
                .landscapeRight,
                .landscapeLeft,
                .portraitUpsideDown(.when(deviceFamilies: [.pad]))
            ]
        )
    ],
    dependencies: [
        .package(url: "https://github.com/simibac/ConfettiSwiftUI", "2.0.2"..<"3.0.0")
    ],
    targets: [
        .executableTarget(
            name: "AppModule",
            dependencies: [
                .product(name: "ConfettiSwiftUI", package: "ConfettiSwiftUI")
            ],
            path: ".",
            swiftSettings: [
                .enableUpcomingFeature("BareSlashRegexLiterals")
            ]
        )
    ]
)

And here is how it looks after renaming the project:

// swift-tools-version:5.3

// WARNING:
// This file is automatically generated.
// Do not edit it by hand because the contents will be replaced.

import PackageDescription
import AppleProductTypes

let package = Package(
    name: "My TEST App",
    platforms: [
        .iOS("18.1"),
        .macOS("11.0"),
        .tvOS("14.0"),
        .watchOS("7.0")
    ],
    products: [
        .library(
            name: "ConfettiSwiftUI",
            targets: ["ConfettiSwiftUI"]
        )
    ],
    targets: [
        .target(
            name: "ConfettiSwiftUI",
            path: "Sources"
        ),
        .testTarget(
            name: "ConfettiSwiftUITests",
            dependencies: [
                "ConfettiSwiftUI"
            ],
            path: "Tests"
        )
    ]
)

Clearly, something's off. This file gets corrupted when changing the app's settings after importing a package.

Workaround solution

To solve this, you'll need to restore this file manually (as far as I know, there's no way to do it in Playgrounds). If you're unfamiliar with this file's format & settings, you can create a new blank Playground with the settings your project needs, then copy the Package.swift file to your old one.

For more information on the warning at the top of this file, here's a relevant thread. I think it's safe to change this file manually in this case, since all you're doing is restoring things back to normal.

Accepted Answer

I was able to reproduce the behavior you described, and I recommend you submit a bug via Feedback Assistant, and make sure to reply with the feedback's ID on this thread for reference. You may also link this thread on your feedback.

Some details about this bug

Swift Playgrounds are a superset of swiftpm (the Swift Package format), and they have a "Package.swift` settings file that you may access via clicking on "Show Package Contents" option in Finder:

This file includes all your App Playground's settings and used packages. Here's how it looks on a functional app, with the same package you were using:

// swift-tools-version: 5.9

// WARNING:
// This file is automatically generated.
// Do not edit it by hand because the contents will be replaced.

import PackageDescription
import AppleProductTypes

let package = Package(
    name: "My App",
    platforms: [
        .iOS("18.1")
    ],
    products: [
        .iOSApplication(
            name: "My App",
            targets: ["AppModule"],
            displayVersion: "1.0",
            bundleVersion: "1",
            appIcon: .placeholder(icon: .palette),
            accentColor: .presetColor(.purple),
            supportedDeviceFamilies: [
                .pad,
                .phone
            ],
            supportedInterfaceOrientations: [
                .portrait,
                .landscapeRight,
                .landscapeLeft,
                .portraitUpsideDown(.when(deviceFamilies: [.pad]))
            ]
        )
    ],
    dependencies: [
        .package(url: "https://github.com/simibac/ConfettiSwiftUI", "2.0.2"..<"3.0.0")
    ],
    targets: [
        .executableTarget(
            name: "AppModule",
            dependencies: [
                .product(name: "ConfettiSwiftUI", package: "ConfettiSwiftUI")
            ],
            path: ".",
            swiftSettings: [
                .enableUpcomingFeature("BareSlashRegexLiterals")
            ]
        )
    ]
)

And here is how it looks after renaming the project:

// swift-tools-version:5.3

// WARNING:
// This file is automatically generated.
// Do not edit it by hand because the contents will be replaced.

import PackageDescription
import AppleProductTypes

let package = Package(
    name: "My TEST App",
    platforms: [
        .iOS("18.1"),
        .macOS("11.0"),
        .tvOS("14.0"),
        .watchOS("7.0")
    ],
    products: [
        .library(
            name: "ConfettiSwiftUI",
            targets: ["ConfettiSwiftUI"]
        )
    ],
    targets: [
        .target(
            name: "ConfettiSwiftUI",
            path: "Sources"
        ),
        .testTarget(
            name: "ConfettiSwiftUITests",
            dependencies: [
                "ConfettiSwiftUI"
            ],
            path: "Tests"
        )
    ]
)

Clearly, something's off. This file gets corrupted when changing the app's settings after importing a package.

Workaround solution

To solve this, you'll need to restore this file manually (as far as I know, there's no way to do it in Playgrounds). If you're unfamiliar with this file's format & settings, you can create a new blank Playground with the settings your project needs, then copy the Package.swift file to your old one.

For more information on the warning at the top of this file, here's a relevant thread. I think it's safe to change this file manually in this case, since all you're doing is restoring things back to normal.

The same here for my complex playground at https://github.com/gui-dos/DiaBLE/tree/main/DiaBLE%20Playground.swiftpm.

Any modification to an app setting disrupts Package.swift: I am importing the CryptoSwift package and the "AppModule" .executableTarget is removed and replaced by the CryptoSwift library and test targets.

I wrote another forum post to describe the problem clearly, and I’d like to report the issue in Feedback Assistant tomorrow.

However, it let me seems impossible to finish my project on time, so maybe the only choice for me is to submit it next year. It’s a pity. 😭

Apple's Respond

Good news that Apple is currently investigating this problem and will fix it in the upcoming update.

Unable to rename the Swift Playground or add an icon when package dependencies is imported
 
 
Q