Skip to content

XCode 16 throws error message ion Defaults code #190

Open

Description

@sarensw

Since updating to XCode 16, the following error is thrown in the Defaults package: "Accessing StateObject's object without being installed on a View. This will create a new instance each time."

image

I'm using the package in one view only:

public let extensionDefaults = UserDefaults(suiteName: "...")!

extension Defaults.Keys {
  public static let isBypass = Key<Bool>("isBypass", default: false, suite: extensionDefaults)
  public static let deviceID = Key<String>("deviceID", default: noneDeviceID, suite: extensionDefaults)
}

struct TabSettingsView: View {
    ...
    @Default(.deviceID) var deviceID: String
    @Default(.isBypass) var isBypass: Bool
    ...
}

Am I using it wrong? Before, in XCode 15, this error did not show up. And I'm using the latest main branch commit.

Activity

  1. sindresorhus commented on Sep 30, 2024

    @sindresorhus
    Owner

    It's either either a false-positive warning or a bug in SwiftUI. Let's see if Xcode 16.1 fixes it.

  2. streamtree commented on Nov 21, 2024

    @streamtree

    Same issue here in 16.1, any time I even access a Defaults value.

  3. cs4alhaider commented on Nov 27, 2024

    @cs4alhaider

    I tried with 8.2.1 and same issue as 9.0.0, when I rollback to 7.1.0 it gone

  4. streamtree commented on Nov 30, 2024

    @streamtree

    Can confirm that 8.0.0 is the culprit. It's not an issue in 7.3.1 but it is in 8.0.0.

  5. cs4alhaider commented on May 24, 2025

    @cs4alhaider

    Still this is an issue still even in 9.0.3, any way we can help? @sindresorhus

  6. added a commit that references this issue on Feb 3, 2026
    7cbc103
  7. sindresorhus commented on Feb 3, 2026

    @sindresorhus
    Owner

    I have a potential fix if anyone would be willing to give it a try: #222

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions