sindresorhus / Defaults

💾 Swifty and modern UserDefaults
https://swiftpackageindex.com/sindresorhus/Defaults/documentation/defaults
MIT License
2.03k stars 121 forks source link

XCode 16 throws error message ion Defaults code #190

Open sarensw opened 1 month ago

sarensw commented 1 month ago

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 commented 1 month ago

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