Learn Courses My Dashboard

Can we have two observable objects

I want to show the user the contacts list as well as location. I wanted to know if we can have two observable objects. one for contacts another for location

Yes you can.

All you need to do is inject the new ObservableObject into the View hierarchy the same way as the other.
Either:

  • @EnvironmentObject
  • @ObservedObject
  • @StateObject

depending on what your needs are and how many Views that require access to the ObservableObject.