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

  • Home
  • SEARCH
  • 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 8228469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:28:01+00:00 2026-06-07T16:28:01+00:00

I have created a class which has a static NSMutableArray, I want this array

  • 0

I have created a class which has a static NSMutableArray, I want this array to be filled with each instance of the class, during my override of init so I don’t have to do anything more coding than I need to.

I should point out the array works perfectly, I am just having trouble storing the correct data.

Does this make sense? If so how can I do this?

Although I have tried doing this

_instance = self;

[[MyClass getStack] addObject:_instance];

It seems I cannot access the instances of the property, and when logged all I get is:

2012-07-14 22:37:58.223 Application[4497:1bb03] <MyClass: 0x92cfc70>

Edit with more code:

My .h file:

@interface MyClass : NSObject

+ (NSMutableArray *)getStack;

My .m file:

@interface MyClass ()

@end

static NSMutableArray *stack;

@implementation MyClass

Edit with image of crash

When logging the array property NSLog(@"%@", [[[MyClass stack] objectAtIndex:0] adam]); It crashes on that line and gives me the following error.

Crash error

  • 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-07T16:28:04+00:00Added an answer on June 7, 2026 at 4:28 pm

    It’s easy to add each instance in its init to a global array:

    static NSMutableArray *stack = nil;
    
    @implementation MyClass
    + (void)initialize {
        if (stack == nil)
            stack = [[NSMutableArray alloc] init];
    }
    
    + (id)init {
        self = [super init];
        if (self) {
            [stack addObject:self];
        }
        return self;
    }
    @end
    

    Your problem must be from something else. Either you are not retaining the global array. Or you are not storing your “property” properly (e.g. you are not retaining it). Or something.

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

Sidebar

Related Questions

I have a CustomerRelation class which has a method getInstance() and instance variable i.e
I have a public class which has the following method and instance variable: public
I have a class inside a DLL ( Database.dll ) which has a static
I have created a controller class named TAddAlarmController which has a tableview which consists
I have a helper class in my program which has many static functions used
I have a domain class which has two dates in it and I want
My situation is essentially this: I have a class called Foo which has dependencies
I have a class A, which has a static vector of objects. The objects
I have created a Singleton for my class which contains an instance of MemcachedClient
I have a class which would create a bean and the bean has few

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.