SwiftUI: How to persist @Published variable using UserDefaults?
问题 I want a @Published variable to be persisted, so that it's the same every time when I relaunch my app. I want to use both the @UserDefault and @Published property wrappers on one variable. For example I need a ' @PublishedUserDefault var isLogedIn '. I have the following propertyWrapper import Foundation @propertyWrapper struct UserDefault<T> { let key: String let defaultValue: T init(_ key: String, defaultValue: T) { self.key = key self.defaultValue = defaultValue } var wrappedValue: T { get