1

My app will be used by one user. However, there will be a lot of user related info. So i have a class called User.h/.m and @property many fields. One one instance will be made of this class since only one user will be using the phone.

My question is,

1.should i adopt a singleton design pattern for this class? I don't want to continuously instantiate this class again and again thru out different view controllers.

  1. I'm saving all info about this class using core data. Having said that, does this compel one to use singleton more?

  2. is singleton design pattern the way to go? or should it be using external json file or plist?

Thank you

  • Singleton design will work. But as an add-on you should handle background mode. Like when app goes in background, save all fields data from class user into json and save it somewhere in file. And when you open app again, initialise user class from that json file again. –  Oct 07 '14 at 05:00
  • #1 : If you singleton, all view will be identical. If you modify 1 view, it would reflecte in other view. – user966379 Oct 07 '14 at 05:55
  • @user966379, thank you. I guess judging from people's input, singleton is the way to go. – Keith Gibson Oct 08 '14 at 06:56

1 Answers1

1

Like @iOS Weblineindia said Singleton will do the job just fine. But if you think in different direction, maybe not. Did you consider that your User obj can have more than one Google (lets assume) accounts? How your app wil interact and deal with such social accounts?

Here is the real use case scenario - I have one account when I'm at work (mail, services, drive etc.) and separate one when I'm out of the office. I want them to stay separate. I'm in such position myself now.

Maybe if you hare some more information about your User class logic it'll be easy to answer.

ekostadinov
  • 6,880
  • 3
  • 29
  • 47
  • thank you for your input. I appreciate it. Regarding your point about user logining w/ different ID (corp, pers) that's sorta not a nature of the app i'm trying to build. It's just all personal. Thanks for your input. – Keith Gibson Oct 08 '14 at 06:56