Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dariowskii/keychain_wrapper
a simple KeychainWrapper to get, set, remove any Codable object from Keychain
https://github.com/dariowskii/keychain_wrapper
codable ios keychain keychain-wrapper swift swiftui wrapper
Last synced: 27 days ago
JSON representation
a simple KeychainWrapper to get, set, remove any Codable object from Keychain
- Host: GitHub
- URL: https://github.com/dariowskii/keychain_wrapper
- Owner: dariowskii
- License: gpl-3.0
- Created: 2022-07-21T15:52:31.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-09-12T09:38:32.000Z (over 2 years ago)
- Last Synced: 2024-10-18T13:18:15.519Z (3 months ago)
- Topics: codable, ios, keychain, keychain-wrapper, swift, swiftui, wrapper
- Language: Swift
- Homepage:
- Size: 27.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# keychain_wrapper
A simple KeychainWrapper to get, set, remove any `Codable` object from Keychain!
## Examples
You can `get` a value in this way:
```swift
do {
let myPassword = try KeychainWrapper.shared.get(forKey: "myPasswordKey", expecting: String.self)
} catch {
// handle error
}
// ...
// or without handling error
let myPassword: String? = KeychainWrapper.shared.get(forKey: "myPasswordKey")
```You can `set` a new value for a specific key in this way:
```swift
let myObject: Codable = MyObject()do {
try KeychainWrapper.shared.set(value: myObject, forKey: "myObjectKey")
} catch {
// handle error
}
```You can `remove` a value for a specific key in this way:
```swift
do {
try KeychainWrapper.shared.remove(forKey: "myObjectKey")
} catch {
// handle error
}
```You can remove all the stored values in this way:
```swift
do {
try KeychainWrapper.shared.deleteAll()
} catch {
// handle error
}
```## KeychainItem
You can also use the `KeychainItem` **propertyWrapper** to use the KeychainWrapper quickly and intuitively, in this way:
```swift
class SharedData {
static let shared = SharedData()
private init() {}
@KeychainItem(key: .accessToken)
var accessToken: String?
}// You can use it like normal variable
let myAccessToken = SharedData.shared.accessToken
SharedData.shared.accessToken = "mySecretToken"
```---
Made with ❤️ from [dariowskii](https://www.linkedin.com/in/dario-varriale/)