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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:58:51+00:00 2026-06-08T22:58:51+00:00

In my app I use a class (which is a singleton for now), called

  • 0

In my app I use a class (which is a singleton for now), called ClassA for the example, for managing stuff.

Because it’s a singleton, I used this behavior to get this unique instance in many classes that needs it.

But now, i can’t keep this class as a singleton anymore, I need to have one instance by NSDocument.

So I created an instance of the ClassA on my NSDocument subclass but the problem is for passing this object on classes that needs it.

I have this kind of structure :

Class1 <- Class2 <- Class3 <- Document -> ClassA

I need to have access of the instance of ClassA of Document in Class1.

I can use Dependency Injection to pass ClassA in Class1 by init or setter methods but because Document does not have direct access to Class1, I need to pass it to Class3 then Class2 then Class1.

Is this the only way to do that ? Or are there another better ways to handle it?

  • 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-08T22:58:54+00:00Added an answer on June 8, 2026 at 10:58 pm

    I would say go back to your singleton principle but use the NSDocument as the key into a dictionary of ClassA objects; something like:

    static NSMutableDictionary *_classCache = [[NSMutableDictionary alloc] init];
    
    + (ClassA *)classAForDocument:(NSDocument *)document
    {
        ClassA *classA = [_classCache objectForKey:document];
        if (classA == nil)
        {
           // Initialise with something specific to the document I guess...
            classA = [[ClassA alloc] init];
            [_classCache setObject:classA forKey:document];
        }
        return classA;
    }
    

    This then only requires that Class{1,2,3} know the document they belong to.

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

Sidebar

Related Questions

I have a class which extends android.app.Application , which I use to persist global
This is sets of methods which I use in DatabaseHandler class which extends from
I am developping an Android app, and I need to use java Signature class
if your app use this solution , do do you plan port the app
I have a Django app that use a django-tagging. I need to port this
I've had a ClickOnce app in use for a few months now, but recently
Ok guys I am developing an iPhone app I have a Model class which
I am developing a swing app, where I have a Factory class which provide
In my Activity I use a class which extends from AsyncTask and a parameter
in my Silverlight 4 app, I have a class which contains a list of

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.