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 565929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:55:26+00:00 2026-05-13T12:55:26+00:00

What is a good way to get a reference to singleton objects in Objective-C?

  • 0

What is a good way to get a reference to “singleton” objects in Objective-C? Note, specifically, I am not referring to the singleton pattern, I am referring to objects of which there are normally only one instance. This specifically applies to application models. For example, in a cooking app, I would like a class (RecipeModel) that can give me an NSArray of all the “Recipe” objects in my system.

I wouldn’t want to load these from persistent storage every time — it would make sense to load them once and then cache them in memory (in a variable on this class, in other words). If I do this, several of my classes will probably need a way to get to this instance.

What is the most flexible way to do this? Here are all the options I can think of.

  1. Make RecipeModel a real Singleton, with a +(RecipeModel *) sharedRecipeModel method
  2. Make the allRecipes NSArray accessible via a class method. Each viewController could then create a new RecipeModel and would get the same (static/global) data. +(NSArray *) allRecipes
  3. Create it in appDelegate and use the sharedApplication to get a reference to it
  4. Make sure everything is in interface builder, and use an IBOutlet to pass a copy of the class to my viewController

On other platforms (flex) I would use a DependencyInjection or MVC framework to handle this kind of wiring. I’ve read that objective-c doesn’t “need” a DI framework because it has categories. I don’t know enough to evaluate that, but categories certainly don’t solve this problem.

  • 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-05-13T12:55:26+00:00Added an answer on May 13, 2026 at 12:55 pm

    I think you’re over complicating this.

    There is no reason to create a singleton class when all you need is just a generic collection object that all your other objects have access to.

    The best way to give universal access to some object is to park it in the application delegate. In the case you suggested you would have something like:

    @interface mytAppDelegate : NSObject <UIApplicationDelegate> {
       NSMutableArray *recipies;
    ...
    

    Then anywhere in your app you could call:

    UIApplicationDelegate *appDelegate=[[UIApplication sharedApplication] delegate];
    RecipeObj *aRecipe=[appDelegate.recipes objectAtIndex:someIndexValue];
    

    No fuss, no muss.

    If you’re using Core Data you can just park the NSManagedObjectContext object in the app delegate and access that directly. Core Data has enormous optimizations that make it as fast as more primitive hand rolled methods. I wouldn’t bother trying to create a separate array unless you test and find that the direct Core Data is to slow. In the case you gave, it won’t be.

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

Sidebar

Ask A Question

Stats

  • Questions 284k
  • Answers 284k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer First off, just to clarify: creating an array of object… May 13, 2026 at 4:24 pm
  • Editorial Team
    Editorial Team added an answer Your approach should work. The issue you're encountering is your… May 13, 2026 at 4:24 pm
  • Editorial Team
    Editorial Team added an answer The key rule is "fork only when the forking overhead… May 13, 2026 at 4:24 pm

Related Questions

My application will have a per machine (not per user) Startup shortcut. I can
One thing I've run into a few times is a service class (like a
Possible Duplicate: What is so bad about Singletons? It's understandable that many design patterns
I'm trying to fix a design flaw that I recently ran across in some
I'm trying to get better at using MVC/MVP style patterns with my WinForm apps

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.