iCloudStorage is a property wrapper around NSUbiquitousKeyValueStore to easily access your shared UserDefaults.
- Swift 5.9+ (Xcode 15+)
- iOS 13+, macOS 10.15+
dependencies: [
.package(url: "https://github.com/0xWDG/iCloudStorage.git", branch: "main"),
],
targets: [
.target(name: "MyTarget", dependencies: [
.product(name: "iCloudStorage", package: "iCloudStorage"),
]),
]
- In Xcode, open your project and navigate to File → Swift Packages → Add Package Dependency...
- Paste the repository URL (
https://github.com/0xWDG/iCloudStorage
) and click Next. - Click Finish.
import SwiftUI
import iCloudStorage
struct ContentView: View {
@iCloudStorage("key")
var value: String = "default"
var body: some View {
VStack {
Text(value)
Button("Change value") {
value = "Hello there at \(Date())"
}
}
.task {
value = "Hello there"
}
.padding()
}
}
🦋 @0xWDG 🐘 mastodon.social/@0xWDG 🐦 @0xWDG 🧵 @0xWDG 🌐 wesleydegroot.nl 🤖 Discord
Interested learning more about Swift? Check out my blog.