AppStorage
A drop-in replacement for the iOS 14 @AppStorage property wrapper compatible with iOS 13
Install / Use
/learn @xavierLowmiller/AppStorageREADME
AppStorage
A drop-in replacement for the iOS 14 @AppStorage property wrapper.
Features
- [x] 100% identical API as SwiftUI's
@AppStorageproperty wrapper - [x] Fully compatible with iOS 13, macOS Catalina, watchOS 6, tvOS 13
- [x] Automatically updates when the underlying
UserDefaultschanges - [x] Well tested
Usage
// iOS 14
@AppStorage("text") var text = "Default Text"
@AppStorage("magic_number", store: .customUserDefaults) var magicNumber = 42
// iOS 13
@AppStorageCompat("text") var text = "Default Text"
@AppStorageCompat("magic_number", store: .customUserDefaults) var magicNumber = 42
<details><summary>More complete example</summary>
<p>
import SwiftUI
import AppStorage
enum StringEnum: String, Identifiable {
case a, b, c
var id: String { rawValue }
}
enum IntEnum: Int, Identifiable {
case this, that, theOther
var id: Int { rawValue }
}
struct ContentView: View {
@AppStorageCompat("text", store: .standard) var text = "Default Text"
@AppStorageCompat("string_enum") var selectionString: StringEnum = .a
@AppStorageCompat("int_enum") var selectionInt: IntEnum = .this
var body: some View {
List {
Section(header: Text("Acts like a persistent @State")) {
TextField("Change me", text: $text)
TextField("Change me, too!", text: $text)
}
Section(header: Text("Change UserDefaults without property wrapper")) {
Button("Sneakily change a UserDefault") {
UserDefaults.standard.setValue("One more thing...", forKey: "text")
}
Button("Remove a UserDefault") {
UserDefaults.standard.setValue(nil, forKey: "text")
}
}
Section(header: Text("Enums with raw values")) {
Picker("Pick Me", selection: $selectionString) {
Text("a").tag(StringEnum.a)
Text("b").tag(StringEnum.b)
Text("c").tag(StringEnum.c)
}.pickerStyle(SegmentedPickerStyle())
Picker("Pick Me", selection: $selectionInt) {
Text("this").tag(IntEnum.this)
Text("that").tag(IntEnum.that)
Text("the other").tag(IntEnum.theOther)
}.pickerStyle(SegmentedPickerStyle())
}
}.listStyle(GroupedListStyle())
}
}
<img src="https://github.com/xavierLowmiller/AppStorage/raw/main/Images/Example.gif" width="375">
</p>
</details>
Installation
Swift Package Manager
Add the package to your Package.swift file:
dependencies: [
.package(url: "https://github.com/xavierLowmiller/AppStorage.git", .upToNextMajor(from: "1.0.4"))
]
CocoaPods
Add the pod to your Podfile:
platform :ios, '13.0'
use_frameworks!
target 'MyApp' do
pod 'AppStorage', '~> 1.0.4'
end
Carthage
Add this line to your Cartfile:
github "xavierLowmiller/AppStorage" ~> 1.0.4
Manual
Since it's just a single file, you can just download and drag it to your project.
Related Skills
node-connect
345.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
104.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
345.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
345.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
