{"id":51228016,"url":"https://github.com/edonv/user-default-entries","last_synced_at":"2026-06-28T13:02:11.419Z","repository":{"id":363778599,"uuid":"1264182697","full_name":"edonv/user-default-entries","owner":"edonv","description":"SwiftUI property wrapper for type-safe and key-safe use of UserDefaults.","archived":false,"fork":false,"pushed_at":"2026-06-11T14:20:23.000Z","size":48,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-17T14:34:20.082Z","etag":null,"topics":["propertywrapper","swift","swiftui","userdefaults"],"latest_commit_sha":null,"homepage":"https://swiftpackageindex.com/edonv/user-default-entries","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/edonv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"edonv","buy_me_a_coffee":"edonv","thanks_dev":"u/gh/edonv"}},"created_at":"2026-06-09T16:31:48.000Z","updated_at":"2026-06-11T14:23:15.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/edonv/user-default-entries","commit_stats":null,"previous_names":["edonv/user-default-entries"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/edonv/user-default-entries","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edonv%2Fuser-default-entries","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edonv%2Fuser-default-entries/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edonv%2Fuser-default-entries/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edonv%2Fuser-default-entries/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edonv","download_url":"https://codeload.github.com/edonv/user-default-entries/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edonv%2Fuser-default-entries/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34889047,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-28T02:00:05.809Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["propertywrapper","swift","swiftui","userdefaults"],"created_at":"2026-06-28T13:02:07.327Z","updated_at":"2026-06-28T13:02:11.410Z","avatar_url":"https://github.com/edonv.png","language":"Swift","funding_links":["https://github.com/sponsors/edonv","https://buymeacoffee.com/edonv","https://thanks.dev/u/gh/edonv"],"categories":[],"sub_categories":[],"readme":"# User Default Entries\n\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fedonv%2Fuser-default-entries%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/edonv/user-default-entries)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fedonv%2Fuser-default-entries%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/edonv/user-default-entries)\n\n## Usage\n\n```swift\n.package(url: \"https://github.com/edonv/user-default-entries.git\", from: \"0.0.0\")\n```\n\n```swift\n.product(name: \"UserDefault\", package: \"user-default-entries\")\n```\n\n### Macro vs Manual\n\nTo use the `@UserDefault` property wrapper, you need to have added a `get`/`set` property to `UserDefaults` via an extension. These can be defined manually or with the packaged `@DefaultEntry` macro.\n\nMacro:\n\n```swift\nimport DefaultEntry\n\nextension UserDefaults {\n    @DefaultEntry(default: \"defaultValue\")\n    var exampleWithDefault: String\n\n    @DefaultEntry\u003cString\u003e\n    var exampleWithoutDefault: String?\n\n    @DefaultEntry(default: 123)\n    var exampleIntWithDefault: Int\n\n    @DefaultEntry\u003cInt\u003e(prefixedWith: \"customPrefix_\")\n    var exampleIntWithoutDefault: Int?\n}\n```\n\nwould be equivalent to the following output:\n\n```swift\nextension UserDefaults {\n    var exampleWithDefault: String {\n        get { String(withKey: \"key_exampleWithDefault\", in: self) ?? \"defaultValue\" }\n        set { newValue.store(in: self, withKey: \"key_exampleWithDefault\") }\n    }\n    \n    var exampleWithoutDefault: String? {\n        get { String(withKey: \"key_exampleWithoutDefault\", in: self) }\n        set { newValue.store(in: self, withKey: \"key_exampleWithoutDefault\") }\n    }\n    \n    var exampleIntWithDefault: Int {\n        get { Int(withKey: \"key_exampleIntWithDefault\", in: self) ?? \"defaultValue\" }\n        set { newValue.store(in: self, withKey: \"key_exampleValue\") }\n    }\n    \n    var exampleIntWithoutDefault: Int? {\n        get { Int(withKey: \"customPrefix_exampleIntWithoutDefault\", in: self) }\n        set { newValue.store(in: self, withKey: \"customPrefix_exampleIntWithoutDefault\") }\n    }\n}\n```\n\nThen, in a `SwiftUI` view, you can do the following:\n\n```swift\nimport SwiftUI\nimport UserDefault\n\nstruct ExampleView: View {\n    @UserDefault(\\.exampleWithDefault)\n    private var exampleWithDefault // implied to be a String\n    \n    @UserDefault(\\.exampleWithoutDefault)\n    private var exampleWithoutDefault // implied to be an optional String\n\n    var body: some View {\n        VStack {\n            TextField(\"Example Field\", text: $exampleWithDefault)\n\n            Text(exampleWithoutDefault ?? \"Value is empty\")\n        }        \n    }\n}\n```\n\n### `UserDefaultable`\n\nThe `@UserDefault` property wrapper relies on both the `@DefaultEntry` macro (or manual entry) and the `UserDefaultable` protocol. Any type used must conform to `UserDefaultable`. If it's a custom type, it must explicitly conform to `UserDefaultable` and one of `RawRepresentable` or `Codable`. See the following section for more details on those.\n\n### RawRepresentable/Codable\n\n`UserDefaultable` supports types that conform to `RawRepresentable` (whose `RawValue` types conform to `UserDefaultable`) and `Codable`, but due to Swift language restrictions, you still have to explicitly add conformance of `UserDefaultable` to your own type. The protocol requirements will be automatically synthesized for you.\n\n## Notes\n\n### NSNumber\n\nOut of the box, `NSNumber` is supported by `UserDefaults`, but due to Swift language restrictions when it comes to adding initializers for a protocol to an existing non-final class, it's not possible to add `UserDefaultable` conformance to `NSNumber`. I'd recommend using `Int`, `Float`, or `Double` instead.\n\n## To-Do's\n\n- [x] Write a macro equivalent to `@Entry`\n    - `@UserDefaultsEntry(_ key: String, in userDefaults: UserDefaults? = nil)\n- [ ] Add conformance of `UserDefaultable` to `BinaryInteger` and `BinaryFloatingPoint` types.\n- [ ] Add DocC content from README.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedonv%2Fuser-default-entries","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedonv%2Fuser-default-entries","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedonv%2Fuser-default-entries/lists"}