Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8537249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:51:23+00:00 2026-06-11T10:51:23+00:00

The app I am developing has 10 controllers. I wanted to share some state

  • 0

The app I am developing has 10 controllers. I wanted to share some state information in set up screen to 5 controllers. What is the best strategy from the below options:

  1. Using NSUserdefaults to store the state information and use it.
  2. storing the state information in AppDelegate instance and using it in relavent controllers
  3. Using a singleton instance to maintain the state information and using it at relavent controllers

Which one would be better? Let me know if there are any other options.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:51:24+00:00Added an answer on June 11, 2026 at 10:51 am

    The NSUserDefaults solution is not a bad one, at least if the values are really going to end up there naturally. Certainly forget about the singleton idea, be it a separate singleton class or the app delegate.


    There’s also another possibility, one that decreases coupling between the controllers. Instead of relying on one particular class that would expose the settings as properties, have the needed settings as properties on the individual controllers:

    @interface Controller : UIViewController
    @property(assign) NSUInteger logLevel; // a sample setting
    @end
    

    Then have one separate class (let’s call it Factory) that would take care of creating the controllers. The factory would keep note of all the settings and pass the controller the settings it needs. (There’s a sample Xcode project on GitHub showing the Factory approach, but for now it doesn’t contain an example of this particular problem.)

    The advantage of this solution is loose coupling, you don’t need an extra object (the app delegate, NSUserDefaults instance or some Settings class instance) to tweak the behaviour of the controller. The downside is a more verbose controller API. Whether to choose this approach or not depends on the nature of your settings.

    Of course, it is also possible to come up with a hybrid solution. Create a Settings class that would keep all the settings, exposing them with a nice API (no more -objectForKey: calls), and share a pointer to a Settings object to all controllers. You don’t need a singleton for this, see the GitHub sample code linked above. This means tighter coupling, but less verbosity in the interface.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an app in PHP and at some points the app has
i am developing app which check whether user has selected any screen lock pattern
I developing an app which has the login screen with username and password. Now
A Backbone app which I'm developing has a collection and a model, and associated
I am developing an app that has java files and php files. The java
i'm developing an app that has a jtable and user could start a download.
I'm developing an app that has a model using race results / times etc..
I'm developing an app which has a large amount of related form data to
I'm developing an app that has a few services, which communicate using AIDL. In
i am developing an app which has a evernote integration,everything works perfect but my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.