SwiftWebUI icon indicating copy to clipboard operation
SwiftWebUI copied to clipboard

Adjust for `ObservableObject` being in `Combine`, and `willChange` instead of `didChange`

Open helje5 opened this issue 6 years ago • 8 comments

This might require a little rework.

Combine also has the @Published, though SwiftUI still has the @ObservedObject.

helje5 avatar Oct 18 '19 14:10 helje5

I don't think @ObservedObject in this project is working. Is it? If it should. I had no luck with getting it to compile while having @ObservedObject wrapper somewhere. :/

shial4 avatar Jan 09 '20 13:01 shial4

It should work, here is the sample I was testing with: https://github.com/SwiftWebUI/Tinker2/blob/master/Sources/Tinker2/Views/Tests/BindingTestView.swift

helje5 avatar Jan 09 '20 15:01 helje5

What is this for? #if canImport(Combine) import Combine #elseif canImport(OpenCombine) import OpenCombine #endif

Should I add OpenCombine to the project? I think it is not working due to the fact the Two types ObservableObject are colliding with each others.

shial4 avatar Jan 09 '20 22:01 shial4

I've copy example from here example

That's what I am getting.

Screen Shot 2020-01-10 at 8 52 52 am

Without SwiftWebUI.Obse.... I have error such as:

'ObservableObject' is ambiguous for type lookup in this context

shial4 avatar Jan 09 '20 22:01 shial4

All this is completely unrelated to this issue. OpenCombine is required on Linux, on macOS you can use the regular Combine (but you need Catalina).

helje5 avatar Jan 09 '20 23:01 helje5

What I meant is that I still can't get it to work. Due to errors presented above.

shial4 avatar Jan 09 '20 23:01 shial4

Oh, sorry. Actually it may not work indeed 🤔 That's what the issue is about 😄 I suppose SwiftWebUI is still assuming didChange, but ObservedObject already switched to willChange. Things probably go wrong ...

This might require a little rework.

I'm not sure how much, maybe it isn't actually that bad. Just replacing didChange w/ willChange might work, because WebUI is still working in a transaction. The "will" will still mark the view as dirty and should trigger the diffing.

helje5 avatar Jan 09 '20 23:01 helje5

Resolved compiling issue. By placing ObservableObject in separate file with one import of SwiftWebUI. Now I can work it out what's happening inside. See if and what is required to be corrected

shial4 avatar Jan 10 '20 00:01 shial4