0

I am creating a new app using iOS 6.x

I used the default template for Master-Detail

The question is where do I instantiate my class for storing objects that will be displayed in my UITableView and the detail view once the UITableViewCell is selected

The data is coming from an SQLite database

Do I instantiate it in AppDelegate? or in my ViewController?

software is fun
  • 7,286
  • 18
  • 71
  • 129

1 Answers1

1

If you have a model class instance that your whole app needs to access, you can either put it in the App Delegate, or you can use a singleton. I tend to prefer the singleton approach because in my opinion the app delegate should handle app delegate protocol messages only, but a lot of people get really sniffy about singletons despite the fact that Cocoa is littered with them. Either way it ends up being the same thing - one instance of a class.

jsd
  • 7,673
  • 5
  • 27
  • 47
  • Sorry to be a bother. What is a Singleton? Can you link me to the recommended solution? – software is fun Jul 30 '13 at 19:09
  • A singleton is a class that always has one and only one instance. Any attempt to alloc a new one returns the existing one. Usually in Cocoa you will see things like sharedBlah or defaultBlah. Example: `[NSFileManager sharedManager]`, `[NSUserDefaults standardUserDefaults]`, `[UIDevice currentDevice]`. – jsd Jul 30 '13 at 21:31
  • I am sorry to bother you. Do I just add my own properties and methods as I would in any other class or do all my methods need to be +(id) or +(NSString *) – software is fun Aug 01 '13 at 18:56
  • You can use any kind of properties or methods. If you stick with "@property" declarations then you get the KVO notifications essentially for free. – jsd Aug 01 '13 at 18:57