I am learning more SwiftUI and building some dummy apps. I am trying to transform an @Published property into another @Published property which will be the one that the View uses. The LocationManager is a class that publishes a location retrieved from CoreLocation. The location gets converted into a MKCoordinateRegion which is consumed by MapCameraPosition which is ultimately what the view cares about.
Is this approach a standard pattern in SwiftUI - where we map and assign.
Thank you for the response. In searches for SwiftUI examples on Google and Github, the examples I found simply bound primitive data types from the ViewModel. I haven't found good realistic examples. My search terms may just be incorrect.
I did intend @Observable from Observation as I am using Swift 5.9 features. From the WWDC they seem to treat the new @Observable macro practically the same as conformance to ObservableObject. However, I don't mind using the older method.
After exploring some more, I realise that if the LocationManager has a completion closure that returns the location, it will simplify the bindings. That way, the LocationManager does not need to be Observable. If it was updating constantly with the user's live location, making the location Observable may be better.
I think it will be easier to start with the old API. But if you are not in hurry, it would be worth learning the new API. That said, it's important to have a good understanding of the solution to this question.
If I understand it correctly, you meant you can avoid the original question by using just one Observable, right? But I still think it's important to figure out the original question.