NSArray to NSMutableArray

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

  1. macrumors 68000

    Joined:
    Sep 8, 2006
    #1
    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.
    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.

    Thanks.
     
  2. macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #2
    Code:
    [NSMutableArray arrayWithArray:(NSArray *)] 
    
    should work for whatever you need to do.
     
  3. macrumors 604

    ArtOfWarfare

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

    Joined:
    Sep 8, 2006
    #4
    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.

    Thanks.
     

Share This Page