{"id":1002,"url":"https://github.com/nmdias/DefaultsKit","last_synced_at":"2025-08-06T13:32:13.852Z","repository":{"id":24173899,"uuid":"100801144","full_name":"nmdias/DefaultsKit","owner":"nmdias","description":"Simple, Strongly Typed UserDefaults for iOS, macOS and tvOS","archived":false,"fork":false,"pushed_at":"2024-11-18T20:23:10.000Z","size":174,"stargazers_count":1432,"open_issues_count":5,"forks_count":95,"subscribers_count":14,"default_branch":"main","last_synced_at":"2024-11-30T01:04:45.198Z","etag":null,"topics":["ios","macos","swift","swift-framework","swift4","tvos","userdefaults"],"latest_commit_sha":null,"homepage":"","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/nmdias.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}},"created_at":"2017-08-19T14:51:15.000Z","updated_at":"2024-11-18T20:23:14.000Z","dependencies_parsed_at":"2024-11-30T01:04:35.651Z","dependency_job_id":"106adc5e-83ae-4078-92ba-7b3b65d5b054","html_url":"https://github.com/nmdias/DefaultsKit","commit_stats":{"total_commits":53,"total_committers":9,"mean_commits":5.888888888888889,"dds":"0.18867924528301883","last_synced_commit":"c51ad1d66c4a84f26330399046b72c76cd39ddfd"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmdias%2FDefaultsKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmdias%2FDefaultsKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmdias%2FDefaultsKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmdias%2FDefaultsKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nmdias","download_url":"https://codeload.github.com/nmdias/DefaultsKit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228548593,"owners_count":17935223,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["ios","macos","swift","swift-framework","swift4","tvos","userdefaults"],"created_at":"2024-01-05T20:15:36.712Z","updated_at":"2024-12-09T14:30:48.784Z","avatar_url":"https://github.com/nmdias.png","language":"Swift","readme":"![DefaultsKit](/DefaultsKit.png?raw=true)\n\n[![CI](https://github.com/nmdias/DefaultsKit/actions/workflows/ci.yml/badge.svg)](https://github.com/nmdias/DefaultsKit/actions)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fnmdias%2FDefaultsKit%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/nmdias/DefaultsKit)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fnmdias%2FDefaultsKit%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/nmdias/DefaultsKit)\n\n[![cocoapods compatible](https://img.shields.io/badge/cocoapods-compatible-brightgreen.svg)](https://cocoapods.org/pods/DefaultsKit)\n[![carthage compatible](https://img.shields.io/badge/carthage-compatible-brightgreen.svg)](https://github.com/Carthage/Carthage)\n\n[简体中文](README.zh-CN.md)\n\nDefaultsKit is a lightweight Swift library that builds on [Codable](https://developer.apple.com/documentation/swift/codable) to offer a **Simple**, **Strongly Typed** and compact wrapper for [UserDefaults](https://developer.apple.com/documentation/foundation/userdefaults). With fewer than 100 lines of code, it’s both easy to use and highly efficient.\n\nInstallation \u003e\u003e [`instructions`](https://github.com/nmdias/DefaultsKit/blob/master/INSTALL.md) \u003c\u003c\n\n## Usage\n\nInstantiate, or get a `shared` instance of `Defaults`\n\n```swift\nlet defaults = Defaults() // or Defaults.shared\n```\n\nThen:\n\n```swift\n// Define a key\nlet key = Key\u003cString\u003e(\"someKey\")\n\n// Set a value\ndefaults.set(\"Codable FTW 😃\", for: key)\n\n// Read the value back\ndefaults.get(for: key) // Output: Codable FTW 😃\n```\n\n### Check if a key has a value:\n\n```swift\nif defaults.has(key) {\n    // Do your thing\n}\n```\n\n\u003e If you just need to know that a key/value pair exists, **without actually using the value**, use the `has()` method instead of the optional `get(for:key)`. For complex objects it will prevent any unnecessary deserialization.\n\n### Implicit Member Expression\n\nYou can find a convenience wrapper for your keys by extending `DefaultsKey`. This allows you use [Implicit Member Expression](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/implicit-member-expression):\n\n```swift\n// Extend with a custom key\nextension DefaultsKey {\n    static var someKey: Key\u003cInt\u003e { Key(\"someKey\") }\n}\n\n// Then use it like this\ndefaults.set(\"Some key\", for: .someKey)\ndefaults.get(for: .someKey) // Output: Some key\n```\n\n### Complex objects\n\nTo store a complex object just conform to the [Codable](https://developer.apple.com/documentation/swift/codable) protocol:\n\n```swift\nstruct Person: Codable {\n    let name: String\n    let age: Int\n}\n```\n\nThen:\n\n```swift\n// Create a key\nlet key = Key\u003cPerson\u003e(\"personKey\")\n\n// Get an instance of your Codable conforming enum, struct or class\nlet person = Person(name: \"Bonnie Greenwell\", age: 80)\n\n// Set the value\ndefaults.set(person, for: key)\n```\n\nAnd finally:\n\n```swift\n// Read it back\nlet person = defaults.get(for: key)\nperson?.name // Bonnie Greenwell\nperson?.age  // 80\n```\n\n### Nested Objects\n\nYou can also use nested objects as long as they conform to the `Codable` protocol:\n\n```swift\nenum Pet: String, Codable {\n    case cat\n    case dog\n}\n\nstruct Person: Codable {\n    let name: String\n    let pets: [Pet]\n}\n\n// Get a Codable conforming instante\nlet person = Person(name: \"Claire\", pets: [.cat])\n\n// Set the value\ndefaults.set(person, for: key)\n\n// And read it back\nlet person = defaults.get(for: key)\nperson?.name        // Claire\nperson?.pets.first  // cat\n```\n\n## License\n\nDefaultsKit is released under the MIT license. See [LICENSE](https://github.com/nmdias/DefaultsKit/blob/master/LICENSE) for details.\n\n### Help Wanted\n\n#### Review/Translate [README.zh-CN.md](README.zh-CN.md) to Chinese\n\nChinese is the #1 spoken language in the world and I'd love to have DefaultsKit be more inclusive, unfortunately I don't speak Chinese. If you know chinese, and would like to help out, please see [issue #1](https://github.com/nmdias/DefaultsKit/issues/1)\n\nThank you 🙏\n","funding_links":[],"categories":["Database","Libs","HarmonyOS","Swift","Data Management [🔝](#readme)"],"sub_categories":["Getting Started","Data Management","Windows Manager","Other free courses","Linter"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnmdias%2FDefaultsKit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnmdias%2FDefaultsKit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnmdias%2FDefaultsKit/lists"}