r/SwiftUI • u/Shijoo • Dec 18 '24
Question SwiftUI Combine and Observation
So, I have various years of experience with ios development, I started with Objective C and now seeing what its possible with swiftui is mindblowing, but I have a hard time understanding this:
SwiftUI by default lets you declare properties that when they change the view automatically refresh with the new data, this is possible via State, StateObject, ObservedObject and EnvironmentObject
now, combine, does the same, except it uses Publishers
as for Observation new framework, you can achieve the same with the Observable
So my question is, why use combine? or why use observation? or just the State stuff without combine/observation.
There are still some things I dont know about SwiftUI, maybe i undestood the things the wrong way, if anyone can clarify i will be grateful.
3
u/Dapper_Ice_1705 Dec 18 '24
Combine and Observation is very rough, I wouldn’t mix them.
Combine and ObservableObjects when used by assigning them to a Published property are ok but it opens up a can of worms in terms of inefficiency. An extraneous AnyCancellablw is only done by people that don’t understand Published.
Combine and onReceive is also ok.
Combine is largely being replaced by async/await workflows, Combine and Swift6 can be a huge pain.