NSMutableArray copy problem
-
Hi all, i have two different NSMutableArray one is source array and other is backup array, on some action copy the source array value to backup array. than continue the changes in source array objects. but here the backup array objects value automatically changed as i changed in source array. please help me i don't want to change backup array object even i change in source array object. thanks in advance.
-
Hi all, i have two different NSMutableArray one is source array and other is backup array, on some action copy the source array value to backup array. than continue the changes in source array objects. but here the backup array objects value automatically changed as i changed in source array. please help me i don't want to change backup array object even i change in source array object. thanks in advance.
-
I do not know Objective-C or Swift, but your description sounds like you have copied the object references instead of the actual content.
-
As I stated in my previous message, "I do not know Objective-C or Swift". So you need to look at what your code is actually doing and why it is not doing deep copy operations. Hint: you could always try the documentation for whichever language you are using.
-
As I stated in my previous message, "I do not know Objective-C or Swift". So you need to look at what your code is actually doing and why it is not doing deep copy operations. Hint: you could always try the documentation for whichever language you are using.
You need to clone the contents of the source array. [copy] method of NSMutableArray makes a reference copy with new array variable hence your content in backup array gets updated when you update source array. Use
NSMutableArray initWithArray
to create a clone of source array but with new reference pointer to it. Hope it helps.
-
You need to clone the contents of the source array. [copy] method of NSMutableArray makes a reference copy with new array variable hence your content in backup array gets updated when you update source array. Use
NSMutableArray initWithArray
to create a clone of source array but with new reference pointer to it. Hope it helps.