stanfordspezi/spezistorage
This source file is part of the Stanford Spezi open-source project.
Setup
You need to add the Spezi Storage Swift package to your app in Xcode or Swift package.
[!IMPORTANT] If your application is not yet configured to use Spezi, follow the Spezi setup article to set up the core Spezi infrastructure.
You can configure the LocalStorage or KeychainStorage module in the SpeziAppDelegate.
[!IMPORTANT] If you use SpeziStorage on the macOS platform, ensure to add the
Keychain Access Groupsentitlement to the enclosing Xcode project via PROJECT_NAME > Signing&Capabilities > + Capability. The array of keychain groups can be left empty, only the base entitlement is required.
import Spezi
import SpeziLocalStorage
import SpeziKeychainStorage
class ExampleDelegate: SpeziAppDelegate {
override var configuration: Configuration {
Configuration {
LocalStorage()
KeychainStorage()
// ...
}
}
}You can then use the LocalStorage or KeychainStorage class in any SwiftUI view.
struct ExampleStorageView: View {
@Environment(LocalStorage.self) var localStorage
@Environment(KeychainStorage.self) var keychainStorage
var body: some View {
// ...
}
}Alternatively, it is common to use the LocalStorage or KeychainStorage module in other modules as a dependency: Spezi Module dependencies.
Local Storage
The LocalStorage module enables the on-disk storage of data in mobile applications.
The LocalStorage module defaults to storing data encrypted supported by the KeychainStorage module. The LocalStorageKey type is used to define storage entries, and specify how data should be persisted.
Keychain Storage
The KeychainStorage module allows for the encrypted storage of small chunks of sensitive user data, such as usernames and passwords for internet services, or cryptographic keys, using Apple's Keychain documentation.
Credentials can be stored in the Secure Enclave (if available) or the Keychain. Credentials stored in the Keychain can be made synchronizable between different instances of user devices.
Handling Credentials
Use the KeychainStorage module to store a set of Credentials instances in the Keychain associated with a server that is synchronizable between different devices.
Handling Keys
Similar to Credentials instances, you can also use the KeychainStorage module to interact with cryptographic keys.
For more information, please refer to the API documentation.
The Spezi Template Application
The Spezi Template Application provides a great starting point and example using the Spezi Storage module.
Contributing
Contributions to this project are welcome. Please make sure to read the contribution guidelines and the contributor covenant code of conduct first.
License
This project is licensed under the MIT License. See Licenses for more information.
[Spezi Footer] [Spezi Footer]
Package Metadata
Repository: stanfordspezi/spezistorage
Default branch: main
README: README.md