or Connect
AppleInsider › Forums › Software › Mac OS X › What is one level copy in objective c?.
New Posts  All Forums:Forum Nav:

What is one level copy in objective c?.

post #1 of 3
Thread Starter 
Well obviously i'm new to this language, stumbled upon this doubt which i hope it will get cleared here .

Reffering http://developer.apple.com/library/m...s/Copying.html.

Under title : "Copying and Mutability"

I'm unable to understand what is meant here by deeper levels, or surface levels of copying. can anyone explain ?...

Thanks in advance .
post #2 of 3
They are talking about levels in a hierarchy of data. Surface level would be the highest up references to data objects e.g the keys in the highest array, second level would be the data those keys point to, deeper levels would be the data contained in second-level data if any e.g if there is another array.

Shallow copy only gives you a unique copy of pointers to data
Deep copy gives you unique pointers and unique second-level data but deeper levels not immutable
True deep copy is entirely unique even for arrays of arrays and requires an archive/unarchive process:

NSArray* trueDeepCopyArray = [NSKeyedUnarchiver unarchiveObjectWithData:
[NSKeyedArchiver archivedDataWithRootObject: oldArray]];

In the following: [item1:"Tim", item2:37, item3:[job:"CEO", salary:"$1"]]

Surface would be identifiers item1 etc, level 2 would be Tim and 37. Deeper levels would be the contents of item3.

You just need to make sure that when you make a copy of a complex data set that it's unique when you need it to be, by using the right copying function to prevent modifications to the copied set affecting the original or vice versa. The same is true in most languages but recursive deep copy can create a recursive loop if there are references to the object itself so having different levels of copying makes some sense.

Your best bet would be to experiment with a data set containing arrays of arrays, run the various copy types and see what effect changes to the copy has on both sets.
post #3 of 3
Thread Starter 
Thanks for that info. Made sense now.
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Mac OS X
AppleInsider › Forums › Software › Mac OS X › What is one level copy in objective c?.