ios - Can't make NSArray deep copy -


a user on app can select filters narrow down items. once filters selected, nsnotification sent passes array of selected filters (nsstrings) view controller.

when receive notification, can extract array [notification userinfo]. now, want compare new filters saved user, make call server if different. here's method:

- (void)applyfilters:(nsnotification *)notification {      nsarray *filters = [[notification userinfo] objectforkey:@"filters"];      if (showmyitems) {          if (![[nsset setwitharray:filters] isequaltoset:[nsset setwitharray:[[pfuser currentuser] objectforkey:@"filtersmy"]]]) {              [[pfuser currentuser] setobject:[nsarray arraywitharray:filters] forkey:@"filtersmy"];             [[pfuser currentuser] saveinbackground];         }      } else {          if (![[nsset setwitharray:filters] isequaltoset:[nsset setwitharray:[[pfuser currentuser] objectforkey:@"filters"]]]) {              [[pfuser currentuser] setobject:[nsarray arraywitharray:filters] forkey:@"filters"];             [[pfuser currentuser] saveinbackground];         }     } } 

here i'm comparing nssets rather nsarrays because order of objects/strings not important. try create new array , set user's new filters via arraywitharray:. so, when next time user changes filter selection, expect new filters array different 1 saved user (my if statement condition). however, when nslog both (new , saved/fetched arrays), same! , therefore if condition never passes.

my explanation of [nsarray arraywitharray:filters] somehow still pointing filters array.

i tried [nskeyedunarchiver unarchiveobjectwithdata:[nskeyedarchiver archiveddatawithrootobject:filters]] suggested on , apple, result same.

can please spot problem? i'm out of options , ideas...

update:

i have pasted full method (above). bit more background:

  • i using 2 instances of same uiviewcontroller class
  • in 1 instance, showmyitems set yes (so top part of if statement called). in instance - no, lower part called
  • what interesting, when showmyitems no, code works expected! when showmyitems yes, doesn't... although code identical.

any thoughts?

nsarray *temp = [[nsmutablearray alloc] initwitharray:filters copyitems:yes];  

(the above works one-level-deep copy)

for deep copying best way i've found far is

nsmutablearray *deepcopyarray = (nsmutablearray*)cfbridgingrelease(cfpropertylistcreatedeepcopy(kcfallocatordefault, (cfdictionaryref)filters, kcfpropertylistmutablecontainers)); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -