sindresorhus / sindresorhus/Defaults

XCode 16 throws error message ion Defaults code

Open
#190 6 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Swift
Stars
2.5k
Forks
163
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the warning in the shown TabSettingsView with Xcode 16, focusing on the @Default(.deviceID) and @Default(.isBypass) usage and the Defaults package's latest main branch. Done means determining whether the example uses the package incorrectly or the package needs a compatibility fix, with the result supported by a reproducible case.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.