property-wrapper

Is it correct to expect internal updates of a SwiftUI DynamicProperty property wrapper to trigger a view update?

假如想象 提交于 2020-02-13 09:03:29
问题 I'm attempting to create a custom property wrapper supported by SwiftUI, meaning that changes to the corresponding properties values would cause an update to the SwiftUI view. Here is a simplified version of what I have: @propertyWrapper public struct Foo: DynamicProperty { @ObservedObject var observed: SomeObservedObject public var wrappedValue: [SomeValue] { return observed.value } } I see that even if my ObservedObject is contained inside of my custom property wrapper, SwiftUI still

Is it correct to expect internal updates of a SwiftUI DynamicProperty property wrapper to trigger a view update?

佐手、 提交于 2020-02-13 09:03:25
问题 I'm attempting to create a custom property wrapper supported by SwiftUI, meaning that changes to the corresponding properties values would cause an update to the SwiftUI view. Here is a simplified version of what I have: @propertyWrapper public struct Foo: DynamicProperty { @ObservedObject var observed: SomeObservedObject public var wrappedValue: [SomeValue] { return observed.value } } I see that even if my ObservedObject is contained inside of my custom property wrapper, SwiftUI still

Add @Publisher behaviour for computed property

别来无恙 提交于 2019-12-30 12:40:53
问题 I am trying to make a ObservableObject that has properties that wrap a UserDefaults variable. In order to conform to ObservableObject , I need to wrap the properties with @Published . Unfortunately, I cannot apply that to computed properties, as I use for the UserDefaults values. How could I make it work? What do I have to do to achieve @Published behaviour? 回答1: For an existing @Published property Here's one way to do it, you can create a lazy property that returns a publisher derived from

Add @Publisher behaviour for computed property

♀尐吖头ヾ 提交于 2019-12-30 12:40:48
问题 I am trying to make a ObservableObject that has properties that wrap a UserDefaults variable. In order to conform to ObservableObject , I need to wrap the properties with @Published . Unfortunately, I cannot apply that to computed properties, as I use for the UserDefaults values. How could I make it work? What do I have to do to achieve @Published behaviour? 回答1: For an existing @Published property Here's one way to do it, you can create a lazy property that returns a publisher derived from