Avatar
omochimetaru 9/26/2019 3:03 AM
@propertyWrapper public struct ObservableProperty<T> { private let relay: BehaviorRelay<T> public var wrappedValue: T { get { return relay.value } set { relay.accept(newValue) } } public var projectedValue: BehaviorRelay<T> { relay } public init(wrappedValue: T) { self.relay = BehaviorRelay(value: wrappedValue) } } public final class ServiceContainer { @ObservableProperty public var style: Style = Style() } func main() { let _ = serviceContainer.$style.subscribe { (style) in apply(style) } }
3:03 AM
こんな感じですかね