View Full Version : NSArray to NSMutableArray

Feb 18, 2013, 07:48 PM
Just had a quick question.

I have a method in a Class that sorts an array, gets information and then returns an NSArray with this code.

NSMutableArray *itemsFromSkill = [BoilerPlateCode returnItemsForSkill:itemStringLabel withItemList:skillsListDict];

I discovered that I need to add object to the new array called "itemsFromSkill" so I changed it to an NSMutableArray. Should I go back to the method that sorts and returns an NSArray and have it return an NSMutableArray, or does it matter?

I remember a while back reading something about this and this is not the correct way but I can't remember? I think I would need to convert an NSArray to an NSMutableArray with a method like makeMutableCopy or something.

It' not a big deal. I was just wondering.


Feb 19, 2013, 07:32 AM
[NSMutableArray arrayWithArray:(NSArray *)]

should work for whatever you need to do.

Feb 19, 2013, 07:40 AM
Of just add [(code that returns a NSArray * here) mutableCopy];

Feb 19, 2013, 10:10 PM
OK That clears it up. So there is a correct way of doing it. I went a head and convert my method to return an NSMutableArray.