{"id":25082187,"url":"https://github.com/niksativa/storagekit","last_synced_at":"2025-04-15T08:16:11.378Z","repository":{"id":232351326,"uuid":"780998457","full_name":"NikSativa/StorageKit","owner":"NikSativa","description":"Swift library for saving and retrieving data from any kind storage","archived":false,"fork":false,"pushed_at":"2025-03-08T23:13:19.000Z","size":27,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T08:16:04.870Z","etag":null,"topics":["file","inmemory","ios","keychain","propertywrapper","storage","swift","userdefaults","wrapper"],"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/NikSativa.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":"2024-04-02T15:01:26.000Z","updated_at":"2025-03-08T23:13:23.000Z","dependencies_parsed_at":"2025-02-07T05:29:12.028Z","dependency_job_id":"1d98821c-91e1-433c-a72d-5deb6758a3b6","html_url":"https://github.com/NikSativa/StorageKit","commit_stats":null,"previous_names":["niksativa/nstorage"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NikSativa%2FStorageKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NikSativa%2FStorageKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NikSativa%2FStorageKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NikSativa%2FStorageKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NikSativa","download_url":"https://codeload.github.com/NikSativa/StorageKit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249031791,"owners_count":21201357,"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":["file","inmemory","ios","keychain","propertywrapper","storage","swift","userdefaults","wrapper"],"created_at":"2025-02-07T05:29:04.214Z","updated_at":"2025-04-15T08:16:11.358Z","avatar_url":"https://github.com/NikSativa.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# StorageKit\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FNikSativa%2FStorageKit%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/NikSativa/StorageKit)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FNikSativa%2FStorageKit%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/NikSativa/StorageKit)\n\nSwift library for saving and retrieving data from any kind storage.\n\n### Defaults\nWrapper for UserDefaults that allows you to store and retrieve Codable objects.\n\n```swift\nimport FoundationKit\nstruct User: Codable {\n    let name: String\n    let email: String\n    let age: Int\n}\n\nfinal class UserViewModel {\n    @Defaults(\"user\", defaultValue: nil)\n    var user: User? {\n        didSet {\n            print(\"new user: \\(user)\")\n        }\n    }\n}\n```\n\n## UserDefaultsStorage\n\nA storage that provides methods to save and retrieve data from UserDefaults.\n\n```swift\nlet storage = UserDefaultsStorage\u003cInt?\u003e(key: \"MyKey\")\nstorage.value = 1\n```\n\n## FileStorage\n\nA storage that provides methods to save and retrieve data from file system. It uses `FileManager` to interact with file system.\nDefault path mask is: ./*userDomainMask*/*cachesDirectory*/**Storages**/*fileName*.stg\n\n```swift\nlet storage = FileStorage\u003cInt\u003e(fileName: \"TestFile.txt\")\nstorage.value = 1\n```\n\n## InMemoryStorage\n\nA storage that provides methods to save and retrieve data in memory.\n\n```swift\nlet storage = InMemoryStorage\u003cInt\u003e(value: 1)\nstorage.value = 1\n```\n\n## KeychainStorage\n\nA storage that provides methods to save and retrieve data from OS Keychain.\nMost safety storage, but with limitations by [SDK](https://developer.apple.com/documentation/security).  \n\n```swift\nlet storage = KeychainStorage(key: \"MyKey\", configuration: .init(service: Bundle.main.bundleIdentifier ?? \"MyService\")\nstorage.value = auth.token\n```\n\n## AnyStorage\n\nType-erased storage that provides methods to save and retrieve data from any kind storage. Each storage has `toAny()` method which is used to convert specific storage to `AnyStorage`.\n\n```swift\nlet storage = UserDefaultsStorage\u003cInt?\u003e(key: \"MyKey\").toAny()\nstorage.value = 1\n```\n\n## Composition\n\n`AnyStorage\u003cValue\u003e` conforms to `Storage` protocol and can be used in composition with other storages by method `combine()` or global function `zip(storages:)`\n\n```swift\nlet userDefaultsStorage = UserDefaultsStorage\u003cInt?\u003e(value: 1)\nlet inMemoryStorage = InMemoryStorage\u003cInt\u003e(value: 1)\n\nlet combined = inMemoryStorage.combine(userDefaultsStorage) // AnyStorage\u003cInt\u003e\ncombined.value = 1\n```\n\n`zip\u003cValue\u003e(storages: [any Storage\u003cValue\u003e])` is only available in iOS 16 or newer\n```swift\nlet combined = zip(storages: [\n    InMemoryStorage\u003cInt?\u003e(value: 1),\n    UserDefaultsStorage(key: \"MyKey\")\n])\n```\n\n`zip\u003cValue\u003e(storages: [AnyStorage\u003cValue\u003e])` is deprecated in iOS 16 or newer \n```swift\nlet combined = zip(storages: [\n    InMemoryStorage\u003cInt?\u003e(value: 1).toAny(),\n    UserDefaultsStorage(key: \"MyKey\").toAny()\n])\n```\n\n### Expirable\nProperty wrapper that allows you to set expiration time for the value.\n\n```swift\n@Expirable(lifetime: .oneHour) var token: String?\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniksativa%2Fstoragekit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fniksativa%2Fstoragekit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniksativa%2Fstoragekit/lists"}