how to stick a string before all the string objects in an array?

Discussion in 'Mac Programming' started by saleh.hi.62, Nov 7, 2011.

  1. saleh.hi.62 macrumors member

    Joined:
    Jul 25, 2011
    #1
    how to stick a string before all the string objects in an NSAarray?
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    NSArray is immutable, so you can't stick anything anywhere. You could come up with something using arrayWithObject and arrayByAddingObjectsFromArray.

    -Lee
     
  3. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #3
    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.
     
  4. saleh.hi.62 thread starter macrumors member

    Joined:
    Jul 25, 2011
    #4
    Thanks Lee,

    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?
     
  5. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #5
    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.
     
  6. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #6
    "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?
     

Share This Page