0

I've built an iOS 5 iPad app which makes use of a second screen. We have an admin view (on the iPad) and an external view through an HDMI enabled TV connected via the Apple DVI adapter. Both the iPad view and the TV view get the same data updates from a service call which is made every few seconds. We then present the data received as a series of charts; the charted data is presented very differently for the TV and iPad views - but the core dictionary of data is the same. I'm wondering about an elegant way to architect this solution. At the moment I have one of the view controllers (the admin iPad VC) doing the service calls using GCD and then dispatching NSNotifications which update the data (charts) properties on the other (TV) view controller. I'm considering moving the service calls away from the VC and creating a singleton which is initialized in the app controller. I then (somehow) set the two VCs as delegates and they get updated using a simple protocol. I'm not entirely sure if this is a good approach or if I should consider something else? Can I even set both VCs as the delegates of another class or is it typically only one delegate per class instance?

Thanks for any input.

Ben

Ben
  • 91
  • 1
  • 5

1 Answers1

0

Why not abstract the chart data into its own model class, which you can share in both view controllers? The model class can be responsible for fetching the new data. To make the controllers aware of updates, they can either use KVO on the model object, or they can observe notifications sent from the model object when an update occurs, or you can have an array of delegates for the model object and each view controller can be a delegate.

There doesn't seem to be any compelling reason to make it a singleton, although you can if you really want.

Tark
  • 5,153
  • 3
  • 24
  • 23
  • Yes, that's what I'm saying. Creating a model but I'm unsure of the "best practice" to share this model between two active VCs. Regarding the singleton, this is the class which is making the service calls. It's created and init'd at startup and continues to call the server and then updates the two VCs using the model. I don't like to use notifications unless necessary; from experience you can easily end up with a too de-coupled app firing events left, right and centre and no chain of responsiblity. – Ben Feb 22 '12 at 16:44