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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:23:58+00:00 2026-06-06T04:23:58+00:00

I have a property an NSArray property called toolbarButtons that in one instance (when

  • 0

I have a property an NSArray property called toolbarButtons that in one instance (when the UIViewController is modal) it needs to be an NSMutableArray, and when the UIViewController is nonmodal, it needs to simply be an NSArray.

I have initialized the property like this:

@property (nonatomic, copy) NSArray *toolbarButtons;

I am initializing toolbarButtons as follows:

- (void) setToolbarButtons 
{
        UIBarButtonItem *exitButton = [[UIBarButtonItem alloc] initWithTitle:@"Exit" style:UIBarButtonItemStyleBordered target:self action:@selector(exitButtonPushed)];

        toolbarButtonsTemp = (NSMutableArray *)[[NSMutableArray alloc] init];
        [(NSMutableArray*)toolbarButtonsTemp addObject:exitButton];
        self.toolbarButtons = toolbarButtonsTemp;

        [exitButton release]; 
}

Then later on I override the above method in a subclass like this:

- (void) setToolbarButtons 
{
    [super setToolbarButtons];

    UIBarButtonItem *leftFlexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    UIBarButtonItem *toolButton = [[UIBarButtonItem alloc] initWithTitle:@"Tools" style:UIBarButtonItemStyleBordered target:self action:@selector(toolButtonPushed)];

    [(NSMutableArray*)self.toolbarButtons addObject:leftFlexibleSpace];
    [(NSMutableArray*)self.toolbarButtons addObject:toolButton];

    [toolButton release];
    [leftFlexibleSpace release];
}

and I’m getting the following error:

[__NSArrayI addObject:]: unrecognized selector sent to instance

I know there are a ton of work arounds to this, but from a design perspective I’m just wondering if what I’m doing is possible and how to correct my mistake.

  • 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-06T04:24:00+00:00Added an answer on June 6, 2026 at 4:24 am
    @property ( nonatomic, copy ) NSArray* array
    

    means:

    - (void) setArray: (NSArray*) array
    {
        _array = [array copy];
    }
    

    [array copy] always returns an non mutable NSArray, even if array is a NSMutableArray.

    @property ( nonatomic, copy ) NSMutableArray* array
    

    is handled a bit differently:

    - (void) setArray: (NSMutableArray*) array
    {
        _array = [array mutableCopy];
    }
    

    In that case, you can do

    self.array = (NSMutableArray*) [NSArray new];
    

    and array will be assigned with a NSMutableArray, as mutableCopy always returns an NSMutableArray.

    The latter is of course strongly discouraged. It works for now. No guarantee it will work forever.

    Your other choice, besides an NSMutableArray, is to use a strong property and to handle the copies yourself.

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

Sidebar

Related Questions

If I have a property, say an NSArray, that's going to be initialized only
I have a property called data of type NSArray in InventoryFilteredTVC and here's a
I have an NSArray of objects , which has a particular property called name
i have an NSArray which contains custom objects, the objects have an NSString property,
hi i have property named. public bool ShowLabels{get; set;} and one toolbar menu button
I have a property within a class, that I need to iterate through all
I have a property on a class that happens to be a Table<T> .
I have a property inside a class that is getting changed by something. The
I have an object with a readonly property that I am trying to implement
I have a little UIView object, CircleColorView.m, that simply creates a view with a

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.