views:

103

answers:

2

Hi,

I have two tabbar items(views) that use the same data, whats the best solution for getting the data?

  1. Make two fetch request for the same data in each view controller.

  2. Make one fetch request in appDelegate, and use sharedApplication to get to the data in appDelegate. I can use KVO and notifications to notify the views if the data has changed.

If i had to choose, i obviously would go for 2, but i want to make sure i am doing the right thing.

Can anyone tell me if this is the right approach?

A: 

I'm not sure why you'd be sticking data fetching-related stuff inside your app delegate, unless there's a good reason to do it there. (I can't really think of one). Having your view controllers observe the app delegate via KVO seems like a bad code smell to me.

I prefer to create data model classes (sometimes designed as Singletons) and use KVO or notifications with my view controllers. It makes for a cleaner design.

Here's a blog post by someone else on the subject.

Shaggy Frog
A: 

I would recommend you use something like a singleton class. There is a very good example at bit-101 . The good thing about this example is that it extends easily to more complex cases, e.g. more tabs ...

John Smith