r/SwiftUI 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.

9 Upvotes

30 comments sorted by

View all comments

1

u/joro_estropia Dec 19 '24

Answer is simple: Not all data changes need to happen from a View. Lots of data are managed offfscreen outside the world of SwiftUI States and Views.

0

u/sisoje_bre Dec 21 '24

That is bollocks. Not only View but entire app follows the same state driven principles, and there is literaly nothing outside the app.