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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:16:17+00:00 2026-06-05T17:16:17+00:00

I have a collection of Objective-C classes that get sub-classed at a variety of

  • 0

I have a collection of Objective-C classes that get sub-classed at a variety of different depths by a variety of different classes. Once the entire object is initialized (all of the sub-classes init functions have finished), I need to run an “Update Cache” method which then gets Overridden by the sub-classes as needed.

My Problem:
With a variety of different inheritance depths to my class tree, there is no one place where I can put [self UpdateCache] and I can be sure that there is no sub-class that has not been initialized. The only possible solution would be to call [super init] after the initialization of each class so that the parent class is always called last. I want to avoid this as this goes against all guidelines of writing Objective-C. Is there any clean solution to this problem?

Here is an some example code:

@interface ClassA : NSObject

-(void)UpdateCache
@end

@interface ClassB : ClassA

-(void)UpdateCache
@end

@interface ClassC : ClassB

-(void)UpdateCache
@end

Now for the implementation we need to somehow get UpdateCahce to be called after we know all sub classes have initialized regardless of which class has been initialized

@implementation A
-(id)init
{
   if(self = [super init])
   {
       // Placing [self UpdateCache] here would make it be called prior to 
       // B and C's complete init function from being called.
   }
}

-(void)UpdateCache
{

}


@end

@implementation B
-(id)init
{
   if(self = [super init])
   {
       // Placing [self UpdateCache] would result in UpdateChache not being
       // called if you initialized an instance of Class A
   }
}

-(void)UpdateCache
{
   [super UpdateCache];
}

@end

@implementation C
-(id)init
{
   if(self = [super init])
   {
       // Placing [self UpdateCache] would result in UpdateChache not 
       //being called if you initialized an instance of Class A or B
   }
}

-(void)UpdateCache
{
   [super UpdateCache];
}

@end
  • 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-05T17:16:20+00:00Added an answer on June 5, 2026 at 5:16 pm

    Do your sub-classes require unique init method signatures? (e.g. sub-class specific parameters required to initialize the object) If not, following a simple factory-like design pattern may work fine.

    Example of what to add your parent/base class:

    +(id)buildSelf {
        YourParentClass* obj = [[[self alloc] init] autorelease];
        if (obj) {
            [obj updateCache];
        }
        return obj;
    }
    

    Add parameters to it, for all sub-classes to use, if needed.

    Again, if your sub-classes need to support unique init method signatures then this won’t work so well.

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

Sidebar

Related Questions

for example I have collection foo of documents like that: {tag_cloud:[{value:games, count:10}, {value:girls, count:500}]}
I have a collection that use as a cache. How can I limit the
I have a collection of NSObjects that I want to store in a 2D
In Objective-C I need to associate a mutable collection integers (monotonic, non-contiguous, could get
I am using a hierarchy of generic collection classes that derive from an abstract
We have a collection of commercial MFC/C++ applications which we sell using Stingray Objective
I have a Mac OS X App that I need to store objective-c objects
All, BACKGROUND: I have a collection_select statement that displays a dropdown box. OBJECTIVE: I'd
Problem: In my D:/collection folder, I have two types of files, that are 8-digit-number_type.dbf
I have Collection List<Car> . How to compare each item from this collection with

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.