-
-
Save sturdysturge/ab4ee1be08eed6033a5454346c188660 to your computer and use it in GitHub Desktop.
RevDoc DefaultAppStorage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
VStack { | |
StandardAppStorageView() | |
.defaultAppStorage(UserDefaults(suiteName: "group.YourGroupName.YourApp") ?? .standard) | |
GroupAppStorageView() | |
.defaultAppStorage(.standard) | |
} | |
} | |
} | |
struct GroupAppStorageView: View { | |
@AppStorage("Text") var text = "" | |
//Equivalent to: | |
//@AppStorage("Text", store: UserDefaults(suiteName: "group.YourGroupName.YourApp") ?? .standard) var text = "" | |
var body: some View { | |
VStack { | |
TextField("Enter text", text: $text) | |
Text(text) | |
} | |
} | |
} | |
struct StandardAppStorageView: View { | |
@AppStorage("Text") var text = "" | |
var body: some View { | |
VStack { | |
TextField("Enter text", text: $text) | |
Text(text) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment