xcode7 - cloned NSArray gets mutated when I change the original array -


in application, have view apply filters. when come , change filters not press apply button , button, want original filters apply ones before changed them now.

eg. filters - city - a, b, c - applied - saved a,b,c filters came again filters - city - d,e - button pressed - regain a,b,c filters

for doing when viewdidload filterview opened, save filters array clone array

clonedfiltersdata = [[nsmutablearray alloc] initwitharray:[[wmgfiltermanager sharedmanager] arrayfortype:type]]; 

this working fine when change in [[wmgfiltermanager sharedmanager] arrayfortype:type]

like remove filters or something, gets removed original array. can tell how initiate array not affected reference.

add copyitems:yes option initwitharray. in example;

  nsarray *deepcopyarray=[[nsarray alloc] initwitharray:somearray copyitems:yes]; 

you want deep copy, not shallow 1 (which copies pointers).


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -