-
-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Instead of
@ViewModel private var counter: Counter
required init?(coder: NSCoder) {
super.init(coder: coder)
self.counter = Counter()
}a simple:
@ViewModel private var counter = Counter()It doesn't work yet, because it uses the subscript hack to get access to self: https://github.com/thoughtbot/CombineViewModel/blob/main/Sources/CombineViewModel/ViewModel.swift#L20
This magic subscript gets called instead of
wrappedValue, and the “enclosing self” gets passed in
I would try to make it a DynamicProperty in SwiftUI terms, the question is how and when (w/o requiring a special subclass). Maybe using some NSNotification.
It’s possible that I could use a more global swizzle of
viewDidLoad(or some other event) and then use reflection to find theViewModel/ObservedObjectand register it lazily
I think 5.3 has that new _ reflection function which might make the Reflection library unnecessary. Didn't look at it yet
Metadata
Metadata
Assignees
Labels
No labels