SwiftUI collections (list, foreach) accept Results<T: Object> types as input. What exactly are the requirements in this feature?
Hi,
We will be adding support for Combine/SwiftUI next week. I'll inform the thread once the feature is merged with the master branch.
@jsflax any progress? Eagerly waiting to remove all the hacks I've added 馃槶. I'm sure your solution will be more efficient than mine (and happy to give feedback if it'll help).
Oh, I just found the PR: https://github.com/realm/realm-cocoa/pull/6231
@jsflax I was just alerted to a 'feature' of SwiftUI which may make realm tricky to support (or at least will need some documentation). Under the hood, SwiftUI doesn't consider a view changed unless it's data has changed. For structs, this is done by comparing memory, but for objects, it's done by comparing the pointer value (not by calling ==). This means that if you have a mutable object as a property of view, even if objectWillChange is called, it may not actually update the view.
I've attached a project which shows the behavior. Notice how Counter is a mutable class. Even though the property changes and even though objectWillChange is called when the property changes, the view still isn't updated. This is because the class has the same pointer.
I just wanted to make sure you were aware of this project while adding support for SwiftUI. I hope it helps.
Oh and btw, this 'problem' was sent to Apple by a friend who found this bug. They responded and said that it is behaving as expected so is not a bug.
Most helpful comment
Hi,
We will be adding support for Combine/SwiftUI next week. I'll inform the thread once the feature is merged with the master branch.