Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 18, 2013, 08:48 PM   #1
larswik
macrumors 65816
 
Join Date: Sep 2006
NSArray to NSMutableArray

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.
__________________
I know more than yesterday.
Lars
larswik is offline   0 Reply With Quote
Old Feb 19, 2013, 08:32 AM   #2
waterskier2007
macrumors 68000
 
waterskier2007's Avatar
 
Join Date: Jun 2007
Location: White Lake, MI
Send a message via AIM to waterskier2007
Code:
[NSMutableArray arrayWithArray:(NSArray *)]
should work for whatever you need to do.
__________________
2012 Mac Mini, 2.6 GHz, 16GB RAM, 1TB HDD
2.4Ghz 15" Macbook Pro
16 GB iPhone 5 : 32 GB iPhone 4S : 16 GB iPad 3
16 GB Nexus 7 (2012)
waterskier2007 is offline   0 Reply With Quote
Old Feb 19, 2013, 08:40 AM   #3
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
Of just add [(code that returns a NSArray * here) mutableCopy];
ArtOfWarfare is offline   0 Reply With Quote
Old Feb 19, 2013, 11:10 PM   #4
larswik
Thread Starter
macrumors 65816
 
Join Date: Sep 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.

Thanks.
__________________
I know more than yesterday.
Lars
larswik is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
XCode thinks that an NSMutableArray is an NSArray BadWolf13 Mac Programming 2 May 25, 2014 02:35 PM
nsmutablearray tacotester1 iPhone/iPad Programming 6 Apr 10, 2014 05:18 PM
Adding NSNumbers in a NSArray fstigre iPhone/iPad Programming 4 Nov 11, 2012 12:46 PM
NSArray LastObject larswik iPhone/iPad Programming 4 Nov 5, 2012 08:01 PM
What is the difference between NSArray and NSMutableArray anandkumar45 iPhone Tips, Help and Troubleshooting 1 Nov 2, 2012 06:09 AM

Forum Jump

All times are GMT -5. The time now is 12:27 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC