GitShow/sindresorhus/Defaults
sindresorhus

Defaults

πŸ’Ύ Swifty and modern UserDefaults

by sindresorhus
iosmacosnsuserdefaultsstorageswift-packageswift-package-managerswiftui-componentsswifty
Star on GitHubForkWebsite

Swift

2.5k stars163 forks20 contributorsActive Β· 1w agoSince 20189.0.9MIT

Meet the team

See all 20 on GitHub β†’
sindresorhus
sindresorhus127 contributions
hank121314
hank12131415 contributions
kitwtnb
kitwtnb4 contributions
fredyshox
fredyshox3 contributions
leoMehlig
leoMehlig3 contributions
shimastripe
shimastripe2 contributions
LarsJK
LarsJK2 contributions
AnderGoig
AnderGoig1 contribution

Languages

View on GitHub β†’
Swift100%

Commit activity

Last 12 weeks Β· 1 commit

Full graph β†’

Community health

4 of 6 standards met

Community profile β†’
71
βœ“READMEβœ“Licenseβœ“Contributingβœ“Code of Conductβ—‹Issue Templateβ—‹PR Template

Recent PRs & issues

Active Β· 3 in progress Β· Last activity 1w ago
See all on GitHub β†’
NickAtGit
Crash on iCloud sync: swift_task_dealloc LIFO violation in iCloudSynchronizer.enqueueOpenIssue

Summary Apps using with one or more keys declared crash on launch or on foreground/background wake-up with . The abort comes from the Swift Concurrency runtime's task-allocator LIFO check, fired from inside the closure that yields to . The crash is reproducible across iOS 16, 17, and 18, multiple devices, and at least two distinct app versions, so it doesn't look OS- or app-specific. I have 23 byte-identical crash reports with the same offset in and the same line in the consumer. Environment version: 9.0.8 (current). The affected code paths are unchanged since the 9.0 iCloud-sync work landed, so likely affects all 9.x. Reproduces on: iOS 16.7.15 (iPhone X) β€” 10 reports iOS 17.4.1 (iPhone 11) β€” 6 reports iOS 17.7.2 (iPhone 11) β€” 3 reports iOS 17.5.1 (iPhone 13 mini) β€” 3 reports iOS 18.4 (iPhone 13) β€” 1 report (older app build, ) Both (cold launch) and (background wake-up). App declares 31 keys with . iCloud KV-store entitlement is enabled and the affected users have non-default payloads in their remote KV-store (i.e. takes the inner branch, not the empty-guard fast path). Crash signature is the runtime's LIFO bump-allocator check. The fatal-error message that prints to the system log immediately before the abort is the standard Concurrency one (along the lines of "freed pointer was not the last allocation"); it doesn't appear in the crash report itself but should be reproducible in Console. Steps to reproduce This is what's strongly indicated by the corpus; I haven't yet boiled it down to a standalone minimal repro target. 1. Declare several keys (the affected app has 31, but it likely reproduces with fewer). 2. Sign in to iCloud on a device/simulator with the app's iCloud KV-store entitlement active. 3. Populate with non-default values for those keys, so enters the arm (, lines 401–406). 4. Cold-launch the app, or trigger any path that fans out many calls in quick succession (initial registration, , ). 5. Crash in 's closure when the runtime tries to pop the binding. Suspected cause The dangerous composition is the way wraps : When 's parent task is resumed by an unstructured (cross-actor resume) inside an enclosing binding running on a consumer of an , the task allocator's pairing of pushes/pops can end up non-LIFO on unwind. Specifically, the continuation context allocated on the parent task's bump allocator can outlive the TaskLocal binding pushed above it by one frame, and when then pops its binding, the runtime sees the top-of-stack isn't the binding and aborts. Each individual API used here is legal Swift Concurrency; the failure is in the composition. Since this is happening on iOS 16, 17, and 18 in the same way, it isn't a runtime regression on a single OS β€” it's the pattern itself that the runtime fails to pair safely. What might fix it on the side This is just a suggestion β€” not tested. Replacing the pattern with a direct keeps the semantics (block until the main-actor write completes) but removes the cross-actor continuation resume that's tripping the allocator: is available on the package's current minimum platforms (iOS 15+, macOS 12+). I haven't verified this clears the crash in practice β€” I can do that and open a PR if helpful. Notes / things I'm not yet sure about I haven't captured the exact pre-abort fatal-error string from Console for any of the reports yet. The stack alone strongly implies the LIFO check, but the string would close that gap. I haven't -resolved the offset against a local Release build to confirm it lands on the unwind specifically. Happy to do that if it helps. in also spawns an orphaned that isn't stored anywhere β€” separate concern, but worth flagging while looking at this area.

NickAtGit Β· 1mo ago
sarensw
XCode 16 throws error message ion Defaults codeOpenIssue

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: Am I using it wrong? Before, in XCode 15, this error did not show up. And I'm using the latest main branch commit.

sarensw Β· 5mo ago

Recent fixes

View closed PRs β†’
shimastripe
Enable users to specify their preferred Swift syntax options to facilitate a flexible transitionMergedPR

WHAT Support swift-syntax upper bound from 602 to 605 to support 602.x, 603.x and 604.x prereleases. HOW This approach is used in libraries such as pointfree’s; since fixing the Swift syntax version would require updating all dependent libraries at once, this option allows for multiple versions provided there are no breaking changes. I understand how far back we should support, but wouldn’t it be possible to handle updates more flexibly by supporting the latest version and the previous one?

shimastripe Β· 1w ago
hocgin
Please avoid locking SwiftSyntax to a narrow version rangeClosedIssue

Hi, thanks for maintaining this package. This package currently depends on a narrow version range. This can easily cause dependency resolution failures when used together with other Swift packages that also depend on . Because many packages in the Swift ecosystem rely on , strict version constraints often make otherwise compatible packages impossible to use together. Would it be possible to relax the dependency range, or support multiple SwiftSyntax versions with conditional compilation? consider supporting a wider range where possible: Point-Free also wrote a useful article about this topic: https://www.pointfree.co/blog/posts/116-being-a-good-citizen-in-the-land-of-swiftsyntax Relaxing the constraint would make this package easier to compose with other Swift packages and reduce unnecessary SwiftPM dependency conflicts. Thanks!

hocgin Β· 1w ago
sindresorhus
Add `removeDuplicates` option to `Defaults.publisher(keys...)` and `Defaults.publisherAll()`ClosedIssue

Since these publisher are a combination of publishers, users cannot use directly on these publishers, but we can do so internally. Should it be true by default? IssueHunt Summary Backers (Total: $0.00) Submitted pull Requests #858 Improve compatibility with custom implementations Become a backer now! Or submit a pull request to get the deposits! Tips Checkout the Issuehunt explorer to discover more funded issues. Need some help from other developers? Add your repositories on IssueHunt to raise funds.

sindresorhus Β· 1mo ago
Structured data for AI agents

Repository: sindresorhus/Defaults. Description: πŸ’Ύ Swifty and modern UserDefaults Stars: 2475, Forks: 163. Primary language: Swift. Languages: Swift (100%). License: MIT. Homepage: https://swiftpackageindex.com/sindresorhus/Defaults/documentation/defaults Topics: ios, macos, nsuserdefaults, storage, swift-package, swift-package-manager, swiftui-components, swifty, userdefaults. Latest release: 9.0.9 (1w ago). Open PRs: 3, open issues: 19. Last activity: 1w ago. Community health: 71%. Top contributors: sindresorhus, hank121314, kitwtnb, fredyshox, leoMehlig, shimastripe, LarsJK, AnderGoig, drekka, ThatsJustCheesy and others.

Β·@ofershap

Replace github.com with gitshow.dev