Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XCode 16 throws error message ion Defaults code #190

Open
sarensw opened this issue Sep 29, 2024 · 1 comment
Open

XCode 16 throws error message ion Defaults code #190

sarensw opened this issue Sep 29, 2024 · 1 comment

Comments

@sarensw
Copy link

sarensw commented Sep 29, 2024

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.

@sindresorhus
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants