NSArray to NSMutableArray

Discussion in 'Mac Programming' started by larswik, Feb 18, 2013.

  1. larswik macrumors 68000

    Sep 8, 2006
    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.

  2. waterskier2007 macrumors 68000


    Jun 19, 2007
    Novi, MI
    [NSMutableArray arrayWithArray:(NSArray *)] 
    should work for whatever you need to do.
  3. ArtOfWarfare macrumors G3


    Nov 26, 2007
    Of just add [(code that returns a NSArray * here) mutableCopy];
  4. larswik thread starter macrumors 68000

    Sep 8, 2006
    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.


Share This Page