views:

48

answers:

2

hi, if i have 2 NSMutableArray declared in .h, synthesize at .m files, how can i copy whole contents of array 1 to 2? actually the same array.

can tried using this code only:

[self.data addObjectsFromArray:self.temparray]

to copy data from temparray to data.

doesn't seems to work.....

A: 

Did you initialize your self.data at all? I.e. self.data = [NSMutableArray array]; somewhere.

If you did, please post some code.

Eiko
self.data = [NSArray arrayWithContentsOfFile:dataPath];its load from plist, which could be empty at first. i save some table cell contents to another temp array. and than i would like to save it to self.data.
Stefan
or here is what i am trying to do: selected a table cell, save it to array and before controller exit save array to file. now implement an alertview, if its ok is press than the table cell will be save to array. i can only thinking of using a temp array to save the table cell 1st, and when ok is press, transfer the temp array to original array. or is there other better ways?
Stefan
If you edit your question to include the code that would help greatly.
Eiko
A: 
- (NSArray *)arrayByAddingObjectsFromArray:(NSArray *)otherArray

is the method your looking for.

ennuikiller
This gives a new array instead of reusing the existing one. Why should he want to use this over the other?
Eiko
this method doesnt seems to work
Stefan
@Stefan, why don't you tell us what "doesn't seem to work" means.
Firoze Lafeer
hi there, self.temparray is not copying to self.data array.i type the following code only: [self.data arrayByAddingObjectsFromArray:self.tempArray];no errors, but its not copying. thks
Stefan
whats the output of [self.tempArray count] ?
ennuikiller
@Stefan, what are you doing with the array that is returned by -[NSArray arrayByAddingObjectsFromArray]. Are you sure you're not just throwing the new array away?Also, when you say "copy" are you trying to add all the elements of tempArray to self.data? Or are you trying to replace all the elements of self.data with the objects from tempArray?
Firoze Lafeer