{"id":13995158,"url":"https://github.com/CaptureContext/swift-standard-clients","last_synced_at":"2025-07-22T21:32:15.781Z","repository":{"id":63906746,"uuid":"411637151","full_name":"CaptureContext/swift-standard-clients","owner":"CaptureContext","description":"Client declarations and live implementations for standard iOS managers","archived":false,"fork":false,"pushed_at":"2022-01-07T00:16:38.000Z","size":32,"stargazers_count":37,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-11-19T17:59:02.839Z","etag":null,"topics":["analytics","caching","clients","functional-programming","idfa","interfaces","ios","keychain","macos","managers","notifications","protocol-witnesses","swift","tvos","userdefaults","watchos"],"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/CaptureContext.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}},"created_at":"2021-09-29T10:57:22.000Z","updated_at":"2023-08-11T13:26:30.000Z","dependencies_parsed_at":"2022-11-28T22:49:32.324Z","dependency_job_id":null,"html_url":"https://github.com/CaptureContext/swift-standard-clients","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptureContext%2Fswift-standard-clients","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptureContext%2Fswift-standard-clients/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptureContext%2Fswift-standard-clients/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptureContext%2Fswift-standard-clients/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CaptureContext","download_url":"https://codeload.github.com/CaptureContext/swift-standard-clients/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227177798,"owners_count":17743168,"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":["analytics","caching","clients","functional-programming","idfa","interfaces","ios","keychain","macos","managers","notifications","protocol-witnesses","swift","tvos","userdefaults","watchos"],"created_at":"2024-08-09T14:03:16.762Z","updated_at":"2024-11-29T17:31:08.313Z","avatar_url":"https://github.com/CaptureContext.png","language":"Swift","funding_links":[],"categories":["Swift"],"sub_categories":[],"readme":"# swift-standard-clients\n\n[![SwiftPM 5.3](https://img.shields.io/badge/swiftpm-5.3-ED523F.svg?style=flat)](https://swift.org/download/) ![Platforms](https://img.shields.io/badge/Platforms-iOS_13_|_macOS_10.15_|_tvOS_14_|_watchOS_7-ED523F.svg?style=flat) [![@maximkrouk](https://img.shields.io/badge/contact-@capturecontext-1DA1F2.svg?style=flat\u0026logo=twitter)](https://twitter.com/capture_context) \n\nClient declarations and live implementations for standard iOS managers\n\n\u003e  More info about client approach:\n\u003e | Source                                                       | Description                                     |\n\u003e | ------------------------------------------------------------ | ----------------------------------------------- |\n\u003e | [Brandon Williams - Protocol Witnesses](https://www.youtube.com/watch?v=3BVkbWXcFS4) | Talk on App Builders Conference 2019            |\n\u003e | [Pointfree - Protocol Witnesses](https://www.pointfree.co/collections/protocol-witnesses) | Pointfree collection                            |\n\u003e | [pointfree/isowords](https://github.com/pointfreeco/isowords/tree/main/Sources) | Examples of different clients can be found here |\n\n\n\n#### Table of contents\n\n| Description | Interface | Implementations |\n| ------------- | ------------- | ------------- |\n| [Caching](#Caching) | [CacheClient](Sources/CacheClient)  | [MemoryCacheClient](Sources/MemoryCacheClientLive) |\n| [IDFA](#IDFA) | [IDFAPermissionsClient](Sources/IDFAPermissionsClient)  | [IDFAPermissionsClientLive](Sources/IDFAPermissionsClientLive) |\n| [Keychain](#Keychain) | [KeychainClient](Sources/KeychainClient)  | [KeychainClientLive](Sources/KeychainClientLive) |\n| [Notifications](#Notifications) | [NotificationsPermissionsClient](Sources/NotificationsPermissionsClient)  | [NotificationsPermissionsClientLive](Sources/NotificationsPermissionsClientLive) |\n| [HapticEngine](#HapticEngine) | [HapticEngineClient](Sources/HapticEngineClient) | [HapticEngineClientLive](Sources/HapticEngineClientLive) |\n| [UserDefaults](#UserDefaults) | [UserDefaultsClient](Sources/UserDefaultsClient)             | [UserDefaultsClientLive](Sources/UserDefaultsClientLive) |\n\n\n\n### Todos\n\n- [ ] Improve readme by adding examples and simplifying descriptions.\n- [ ] Add LocalAuthenticationClient [ _Soon_ ]\n- [ ] Find out if it's better to use `Any`-based UserDefaults storage instead of `DataRepresentable`-based.\n- Add more tests\n  - [ ] Caching\n  - [ ] IDFA\n  - [ ] Keychain\n  - [ ] Notifications\n  - [ ] HapticEngine\n  - [ ] UserDefaults\n  - [x] DataRepresentable\n\n\n\n## Caching\n\n`CacheClient\u003cKey, Value\u003e` is a generic client over hashable key and value, it provides interfaces for the following operations:\n\n- `saveValue(_: Value, forKey: Key)`\n- `loadValue(of: Value.Type = Value.self, forKey: Key) -\u003e Value`\n- `removeValue(forKey: Key)`\n- `removeAllValues()`\n\n#### MemoryCacheClient\n\n`MemoryCacheClient` is build on top of `NSCache`. Under the hood it uses `MemoryCache` wrapper, improved version of [John Sundells' Cache](https://www.swiftbysundell.com/articles/caching-in-swift/). You can use `MemoryCache` (which also provides a way to save itself to disk if your types are codable) directly to build your own `CacheClient` implementations.\n\n\n\n## IDFA\n\n`IDFAPermissionClient` is a client for `ASIdentifierManager` and `ATTrackingManager`, it provides interfaces for the following operations:\n\n- `requestAuthorizationStatus() -\u003e AnyPublisher\u003cAuthorizationStatus, Never\u003e`\n- `requestAuthorization() -\u003e AnyPublisher\u003cAuthorizationStatus, Never\u003e`\n- `requestIDFA() -\u003e AnyPublisher\u003cUUID?, Never\u003e`\n\n\u003e `IDFAPermissionClient.AuthorizationStatus` is a wrapper for `ATTrackingManager.AuthorizationStatus` type and `ASIdentifierManager.isAdvertisingTrackingEnabled` value it's values are:\n\u003e\n\u003e - `notDetermined = \"Not Determined\"`  `// ATTrackingManager.AuthorizationStatus.notDetermined`\n\u003e - `restricted = \"Restricted\"` `// ATTrackingManager.AuthorizationStatus.restricted`\n\u003e - `denied = \"Denied\"` `// ATTrackingManager.AuthorizationStatus.denied`\n\u003e - `authorized = \"Authorized\"` `// ATTrackingManager.AuthorizationStatus.authorized`\n\u003e - `unknown = \"Unknown\"` `// ATTrackingManager.AuthorizationStatus.unknown`\n\u003e - `unavailableWithTrackingEnabled = \"Unavailable: Tracking Enabled\"` `// iOS\u003c14 macOS\u003c11, tvOS\u003c14 ASIdentifierManager.shared().isAdvertisingTrackingEnabled == true`\n\u003e - `unavailableWithTrackingDisabled = \"Unavailable: Tracking Disabled\"` `// iOS\u003c14 macOS\u003c11, tvOS\u003c14 ASIdentifierManager.shared().isAdvertisingTrackingEnabled == false`\n\u003e\n\u003e It also has a computed property `isPermissive` which is `true` for `.authorized` and `.unavailableWithTrackingEnabled`\n\n\n\n## Keychain\n\n`KeychainClient` is a client for Security framework keychain access, it **stores objects as data** (Using [`DataRepresentable`](#DataRepresentable) protocol) and provides interfaces for the following operations:\n\n- `saveValue\u003cValue: DataRepresentable\u003e(_: Value, forKey: Key, policy: AccessPolicy)`\n- `loadValue\u003cValue: DataRepresentable\u003e(of: Value.Type = Value.self, forKey: Key) -\u003e Value`\n- `removeValue(forKey: Key)`\n\n`KeychainClient.Key` can be initialized by `rawValue: Stirng`, `StringLiteral` or `StringInterpolation`. Also you can use `.bundle(_:Key)` or `.bundle(_:Bundle, _:Key)`  to add `bundleID` prefix to your key.\n\n\u003e `KeychainClient.Operations.Save.AccessPolicy` is a wrapper for kSec access constants and it's values are:\n\u003e\n\u003e - `accessibleWhenUnlocked` `// kSecAttrAccessibleWhenUnlocked`\n\u003e - `accessibleWhenUnlockedThisDeviceOnly` `// kSecAttrAccessibleWhenUnlockedThisDeviceOnly`\n\u003e - `accessibleAfterFirstUnlock` `// kSecAttrAccessibleAfterFirstUnlock`\n\u003e - `accessibleAfterFirstUnlockThisDeviceOnly` `// kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly`\n\u003e - `accessibleWhenPasscodeSetThisDeviceOnly` `// kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly`\n\u003e - `accessibleAlways` `// kSecAttrAccessibleAlways`\n\u003e - `accessibleAlwaysThisDeviceOnly` `// kSecAttrAccessibleAlwaysThisDeviceOnly`\n\u003e\n\n\n\n## Notifications\n\n`NotificationsPermissionsClient` is a client for `UNUserNotificationCenter`, it provides interfaces for the following operations:\n\n- `requestAuthorizationStatus() -\u003e AnyPublisher\u003cAuthorizationStatus, Never\u003e`\n- `requestAuthorization(options: AuthorizationOptions) -\u003e AnyPublisher\u003cAuthorizationStatus, Never\u003e`\n- `configureRemoteNotifications(_:)` // Pass `.register` or `.unregister` to the function\n\n\u003e `NotificationsPermissionsClient.AuthorizationStatus` is a wrapper for `UNAuthorizationStatus` type it's values are:\n\u003e\n\u003e - `notDetermined`\n\u003e\n\u003e - `denied`\n\u003e\n\u003e - `authorized`\n\u003e\n\u003e - `provisional`\n\u003e\n\u003e - `ephemeral` `// iOS14+ only`\n\u003e\n\u003e It also has a computed property `isPermissive` which is true for `authorized`, `ephimeral` and `provisional`\n\n\u003e `NotificationsPermissionsClient.AuthorizationOptions` is a wrapper for `UNAuthorizationOptions` type it's predefined values are:\n\u003e\n\u003e - `badge`\n\u003e - `sound`\n\u003e - `alert`\n\u003e - `carPlay`\n\u003e - `criticalAlert`\n\u003e - `providesAppNotificationSettings`\n\u003e - `provisional`\n\u003e - `announcement` `// iOS only`\n\u003e\n\u003e You can also construct `AuthorizationOptions` object by providing `UInt` raw value. \n\n\n\n## HapticEngine\n\n`HapticEngineClient` is a factory-client for `HapticFeedback` clients. `HapticFeedback` is a client for `UIFeedbackGenerator`.\n\n### Usage\n\n```swift\nimport HapticEngineClientLive\n\n// If you need just one generator you can use HapticFeedback directly\nHapticFeedback.success.trigger()\n\n// Otherwise if you need more flexible way to create Haptic feedbacks use HapticEngineClient\nHapticEngineClient.live.generator(for: .success).trigger()\n```\n\n\n\n## UserDefaults\n\n`UserDefaultsClient` is a client for UserDefaults object, it **stores objects as data** (Using [`DataRepresentable`](#DataRepresentable) protocol) and provides interfaces for the following operations:\n\n- `saveValue\u003cValue: DataRepresentable\u003e(_: Value, forKey: Key)`\n- `loadValue\u003cValue: DataRepresentable\u003e(of: Value.Type = Value.self, forKey: Key) -\u003e Value`\n- `removeValue(forKey: Key)`\n\n`UserDefaultsClient.Key` can be initialized by `rawValue: Stirng`, `StringLiteral` or `StringInterpolation`. Also you can use `.bundle(_:Key)` or `.bundle(_:Bundle, _:Key)`  to add `bundleID` prefix to your key.\n\n\n\n## DataRepresentable\n\n[`DataRepresentable`](Sources/DataRepresentable) module provides a protocol for objects data representation. It is used by `UserDefaultsClient` and `KeychainClient` to store objects as data.\n\n\n\n## Installation\n\n### Basic\n\nYou can add StandardClients to an Xcode project by adding it as a package dependency.\n\n1. From the **File** menu, select **Swift Packages › Add Package Dependency…**\n2. Enter [`\"https://github.com/capturecontext/swift-standard-clients.git\"`](https://github.com/capturecontext/swift-standard-clients.git) into the package repository URL text field\n3. Choose products you need to link them to your project.\n\n### Recommended\n\nIf you use SwiftPM for your project, you can add StandardClients to your package file.\n\n```swift\n.package(\n  name: \"swift-standard-clients\",\n  url: \"https://github.com/capturecontext/swift-standard-clients.git\", \n  .upToNextMinor(from: \"0.1.0\")\n)\n```\n\nDo not forget about target dependencies:\n\n```swift\n.product(\n  name: \"SomeClientOrClientLive\", \n  package: \"swift-standard-clients\"\n)\n```\n\n\n\n## License\n\nThis library is released under the MIT license. See [LICENSE](LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCaptureContext%2Fswift-standard-clients","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FCaptureContext%2Fswift-standard-clients","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCaptureContext%2Fswift-standard-clients/lists"}