Separate names with a comma.
Discussion in 'Mac Programming' started by saleh.hi.62, Nov 7, 2011.
how to stick a string before all the string objects in an NSAarray?
NSArray is immutable, so you can't stick anything anywhere. You could come up with something using arrayWithObject and arrayByAddingObjectsFromArray.
NSArray is immutable. So can't be done.
If you mean an NSMutableArray, then:
1. Read the class reference doc.
2. Look for a method that will insert an object at a particular index. (hint: underlined words are clues)
Before posting, always consult the documentation.
but what i mean i this !
i have a NSArray, each element is a string value, i want to add a string before all the strings in my array. is there any function to do that ? or i should do that manually?
NSArray is immutable. Do you know what "immutable" means? It means "can't be changed". Since the NSArray can't be changed, you can't insert anything, you can' remove anything, and you can't change any value already stored there.
If you want a mutable array, you must use NSMutableArray.
"Before all strings" means: Your array contains "A", "B", "C" and you want an array containing "X", "A", "B", "C".
"Before each string" means: Your array contains "A", "B", "C" and you want an array containing "XA", "XB", "XC".
Which one is it? If it is the second, why does it matter that the string are in an array?