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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:04:18+00:00 2026-06-15T14:04:18+00:00

AAA.m: – (void)keepCurrentArray:(id)object { _currentTest=[[NSMutableArray alloc]init]; [_currentTest addObject:@one]; [_currentTest addObject:@two]; [_currentTest addObject:object]; NSLog(@My Array

  • 0

AAA.m:

- (void)keepCurrentArray:(id)object
{
     _currentTest=[[NSMutableArray alloc]init];
    [_currentTest addObject:@"one"];
    [_currentTest addObject:@"two"];
    [_currentTest addObject:object];
    NSLog(@"My Array is:%@",_currentTest);
}

Class BBB.m is passing objects to class AAA.
Right now if i’m passing X to the above method so the array will be: one,two,X . Then i’ll send it Y and the array will be one,two,Y instead of what i want to accomplish: one,two,x,one,two,y.
Is that because I’m alloc and init _currentTest every time? How can I solve it?

Update:
I had a few suggestions on how to solve this and none of them worked for me. I’ve created a new project with just the code in the answers and i’m still getting the same result when I try to add the second object i get: one, two, test instead of one,two,test,one,two,test

  • 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-15T14:04:19+00:00Added an answer on June 15, 2026 at 2:04 pm

    _currentTest=[[NSMutableArray alloc]init]; in a method is never a good thing!!!

    As per naming convention it seems to be a property to the AAA Class. So for property, the alloc+init should be either in init or awakeFromNib. So that if is initialized just once.

    However in some situations init is called more than once then your previous values are lost and new set are added.

    So what you can do is make another class and put this _currentTest Array there and make it static and use it here. I hope this will work fine. And make sure in the init method of that class it is initialized just once, as :

    //**this is not compiled and checked may contains typo and errors**
    
    @implementation Storage
    
    static NSMutableArray *yourStaticArray;
    
    -(id)init{
        self = [super init];
        if (self) {
            if (!yourStaticArray) {
                yourStaticArray=[NSMutableArray new];
            }
        }
        return self;
    }
    
    -(void)addYourStaticArray:(NSString *)val{
        [yourStaticArray addObject:val];
    }
    
    
    -(NSArray *)yourStaticArray {
        return yourStaticArray ;
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: class Array { public: int aaa; Array():aaa(1){} void print()
For code: class a(object): a='aaa' b=a() print hasattr(a,'a') print hasattr(b,'a') who can be called
class a(object): w={'a':'aaa','b':'bbb'} def __iter__(self): return iter(self.w) def next(self):#this is not be called print
class a(object): data={'a':'aaa','b':'bbb','c':'ccc'} def pop(self, key, *args): return self.data.pop(key, *args)#what is this mean. b=a()
class a(object): class b: a='aaa' print a.b.a#print 'aaa' b=a() print b.b.a#print 'aaa'
I have declared: class aaa { public: static std::queue<QPair<void (*)( ... ), int> >
I read in an array of strings such as: aaa bb ccccc ddd eeee
This if(is_object($value)) echo 'AAA'; if(gettype($value)==='object') echo 'BBB' Prints 'BBB'. Specifically, value is __PHP_Incomplete_Class Object
I have two maven projects Project AAA AAA-Core AAA-Other Project BBB BBB-Core BBB-AAA-specific I
I have an application that loads aaa.dll. aaa.dll loads two other dlls bbb.dll and

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.