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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:36:35+00:00 2026-05-31T08:36:35+00:00

I created an NSMutableArray object by NSMutableArray *array = [[NSMutableArray alloc]init]; and used method

  • 0

I created an NSMutableArray object by

NSMutableArray *array = [[NSMutableArray alloc]init];

and used method componentsSeperatedByString: as

array = [myString componentsSeperatedByString:@"++"];

but when I performed operation on array like,

[array removeAllObjects];

I got exception like “removeAllObjects unrecognized selector send to instance”.

I solved this issue by modifying code like,

NSArray *components = [myString componentsSeperatedByString:@"++"];



array = [NSMutableArray arrayWithArray:components];

and I after that could perform operation like

[array removeAllObjects];

My doubt is why did NSMutableArray automaticaqlly converted to NSArray? How Can I avoid automatic type conversion like this, to prevent exceptions? Thanks in advance….

  • 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-05-31T08:36:36+00:00Added an answer on May 31, 2026 at 8:36 am

    There is a mistake in your understanding of how Objective-C works. This line:

    NSMutableArray *array = [[NSMutableArray alloc]init];
    

    allocates and initializes the array, and the pointer array points to this object. Now, this line:

    array = [myString componentsSeperatedByString:@"++"];
    

    makes the array pointer to point to the new array returned by componentsSeparatedByString method. You loose the reference to your alloced and inited mutable array when you do this, and you create the memory leak if you don’t use ARC.

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

Sidebar

Related Questions

I'm a beginner i have some problem with NSArray. I created an array and
Someone please help. I am a noob here who has just created an array
I have a mutable array which stores sprites but the problem is that the
I am confused with releasing the object that I first alloc/initialized and then copied.
I Create a class named DataClass there i have this method +(NSMutableArray*) returnList :(NSString
Hi im trying to retrieve an object of a specific class from an NSMutableArray,
I know indexOfObject could return the index of the element in an array, but
I am trying to add two objects to my array but when i inspect
So I dynamically create 3 UIButtons (for now), with this loop: NSMutableArray *sites =
Created .NET WCF service, tested it - works. Generated schemas from Data and service

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.