{"id":23070233,"url":"https://github.com/markbattistella/defaultskit","last_synced_at":"2026-05-13T11:34:28.644Z","repository":{"id":256680919,"uuid":"799080102","full_name":"markbattistella/DefaultsKit","owner":"markbattistella","description":"DefaultsKit is a Swift package that provides a clean and type-safe way to manage UserDefaults keys and values.","archived":false,"fork":false,"pushed_at":"2026-02-20T22:51:50.000Z","size":44,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-05-06T21:34:13.854Z","etag":null,"topics":["hacktoberfest","ios","ipados","macos","swift","tvos","watchos"],"latest_commit_sha":null,"homepage":"https://swiftpackageindex.com/markbattistella/DefaultsKit/documentation","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/markbattistella.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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},"funding":{"github":["markbattistella"],"custom":["https://www.paypal.me/markbattistella/5AUD","https://www.paypal.me/markbattistella/10AUD","https://www.paypal.me/markbattistella/20AUD"]}},"created_at":"2024-05-11T06:05:40.000Z","updated_at":"2026-01-08T23:34:11.000Z","dependencies_parsed_at":"2024-12-16T06:37:40.213Z","dependency_job_id":null,"html_url":"https://github.com/markbattistella/DefaultsKit","commit_stats":null,"previous_names":["markbattistella/defaultskit"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/markbattistella/DefaultsKit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markbattistella%2FDefaultsKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markbattistella%2FDefaultsKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markbattistella%2FDefaultsKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markbattistella%2FDefaultsKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markbattistella","download_url":"https://codeload.github.com/markbattistella/DefaultsKit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markbattistella%2FDefaultsKit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32980812,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T11:31:52.688Z","status":"ssl_error","status_checked_at":"2026-05-13T11:31:52.072Z","response_time":115,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["hacktoberfest","ios","ipados","macos","swift","tvos","watchos"],"created_at":"2024-12-16T06:25:23.804Z","updated_at":"2026-05-13T11:34:28.624Z","avatar_url":"https://github.com/markbattistella.png","language":"Swift","funding_links":["https://github.com/sponsors/markbattistella","https://www.paypal.me/markbattistella/5AUD","https://www.paypal.me/markbattistella/10AUD","https://www.paypal.me/markbattistella/20AUD"],"categories":[],"sub_categories":[],"readme":"\u003c!-- markdownlint-disable MD033 MD041 --\u003e\n\u003cdiv align=\"center\"\u003e\n\n# DefaultsKit\n\n![Swift Versions](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fmarkbattistella%2FDefaultsKit%2Fbadge%3Ftype%3Dswift-versions)\n\n![Platforms](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fmarkbattistella%2FDefaultsKit%2Fbadge%3Ftype%3Dplatforms)\n\n![Licence](https://img.shields.io/badge/Licence-MIT-white?labelColor=blue\u0026style=flat)\n\n\u003c/div\u003e\n\n`DefaultsKit` is a Swift package that provides a clean and type-safe way to manage `UserDefaults` keys and values. It introduces extensible protocols for keys and convenient property wrappers for storing, retrieving, and managing preferences using a consistent prefix strategy.\n\n## Features\n\n- **Type-safe `UserDefaults` Keys:** Use enums conforming to `UserDefaultsKeyRepresentable` to define keys with automatic prefix handling.\n- Property Wrappers:\n  - `@DefaultsPersisted`: A powerful property wrapper for any `Codable` type with built-in support for primitives and optionals\n  - `@AppStorage:` Enhanced SwiftUI integration with type-safe keys for common types\n- **Prefix Management:** Supports internal bundle identifiers or custom prefixes via the `UserDefaultsKeyRepresentable` protocol.\n- **Utility Functions:** Includes methods for setting, getting, printing, and deleting `UserDefaults` entries\n- **`Codable` Support:** Automatic encoding/decoding for complex types\n\n## Installation\n\nAdd `DefaultsKit` to your Swift project using Swift Package Manager.\n\n```swift\ndependencies: [\n  .package(url: \"https://github.com/markbattistella/DefaultsKit\", from: \"1.0.0\")\n]\n```\n\n## Usage\n\n### Defining Keys\n\nDefine keys by conforming your enums to `UserDefaultsKeyRepresentable`:\n\n```swift\nenum UserDefaultsKey: String, UserDefaultsKeyRepresentable {\n    case userPreference\n    case appTheme\n    case userProfile\n}\n```\n\n### Using DefaultsPersisted\n\nThe `@DefaultsPersisted` property wrapper supports any `Codable` type:\n\n```swift\n// For primitive types\n@DefaultsPersisted(UserDefaultsKey.userPreference)\nvar isEnabled: Bool = false\n\n// For custom types\n@DefaultsPersisted(UserDefaultsKey.userProfile)\nvar profile: UserProfile = UserProfile(name: \"John\", age: 30)\n\n// For optional values\n@DefaultsPersisted(UserDefaultsKey.lastLoginDate)\nvar lastLogin: Date?\n```\n\n### AppStorage Integration\n\nUse type-safe keys with SwiftUI's `@AppStorage`:\n\n```swift\nstruct ContentView: View {\n    @AppStorage(UserDefaultsKey.userPreference)\n    var isEnabled: Bool = false\n    \n    var body: some View {\n        Toggle(\"Enable Feature\", isOn: $isEnabled)\n    }\n}\n```\n\n### Direct UserDefaults Access\n\nUse the extended `UserDefaults` methods:\n\n```swift\n// Setting values\nUserDefaults.standard.set(true, for: UserDefaultsKey.userPreference)\n\n// Getting values\nlet preference = UserDefaults.standard.bool(for: UserDefaultsKey.userPreference)\n\n// Encoding complex objects\ntry? UserDefaults.standard.encode(profile, for: UserDefaultsKey.userProfile)\n\n// Decoding complex objects\nlet savedProfile: UserProfile? = try? UserDefaults.standard.decode(for: UserDefaultsKey.userProfile)\n```\n\n## Managing Defaults\n\n### Registering defaults\n\n```swift\n// Register defaults\nUserDefaults.standard.register(\n    defaults: [\n        UserDefaultsKey.appTheme: \"light\",\n        UserDefaultsKey.userPreference: true\n    ]\n)\n```\n\n### Helper methods\n\n```swift\n// Print all values from the UserDefaultsKey enum\nUserDefaults.printAllKeys(from: UserDefaultsKey.self)\n\n// Delete all values in the UserDefaultsKey enum\nUserDefaults.deleteAllKeys(from: UserDefaultsKey.self)\n```\n\nUsing it this way allows you to segregate different `UserDefaultsKeyRepresentable` enums, and print or delete them.\n\n## License\n\n`DefaultsKit` is available under the MIT license. See the LICENSE file for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkbattistella%2Fdefaultskit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkbattistella%2Fdefaultskit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkbattistella%2Fdefaultskit/lists"}