replace - iOS: copying an object from oldArray to newArray -


i have oldarray consists of many small arrays. want take 1 of these objects (one small array), modify it, , (if user hits button) replace it. that:

step 1 - made new array initialized newarray 1 small object.

openedcartproduct = nil;   openedcartproduct = [nsmutablearray array];  [openedcartproduct addobjectsfromarray: [sharedappdelegate.myengine.shoppingcart objectatindex:indexpath.row]]; 

step 2 - modify array.

[[openedcartproduct objectatindex:0] setobject:[nsnumber numberwithfloat:[inputrabatlabel.text floatvalue]] forkey:krabat_key]; 

step 3 - replace object in oldarray.

in step 2, modification happening in oldarray before replacing object. missing here?

thanks in advance guys! :)

edit: object modified small array consisting of nsmutabledictionary @ index 0 modifying.

edit seems need deep copy here. found solution of hack, works fine, , simple enough:

openedcartproduct = [nskeyedunarchiver unarchiveobjectwithdata:[nskeyedarchiver archiveddatawithrootobject:[sharedappdelegate.myengine.shoppingcart objectatindex:indexpath.row]]]; 

you copying reference original small array. points small array in first array when change it. contains original contents. if want alter without changing in first array, need perform copy, , in case deep copy, since contains mutabledictionary (that assume want copy).


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -