title: How to copy a custom Objective-C object?
body: <p>I have a class, say the class Person. In than class I have several NSMutableArrays.</p>
  
  <pre><code>@property NSMutableArray *arrayOne;
  @property NSMutableArray *arrayTwo;
  ...
  </code></pre>
  
  <p>Now I want to copy that Class so I can return it from a function and use the copy and change it's data. I want to have a new copy of the object in memory not another reference to the same address.</p>
  
  <p>To do that I have implemented this in my Person.m:</p>
  
  <pre><code>-(id)copyWithZone:(NSZone *)zone
  {
      Person *copy = [[Person allocWithZone:zone] init;
      copy.arrayOne = [NSMutableArray arrayWithArray:self.arrayOne];
      copy.arrayTwo = [NSMutableArray arrayWithArray:self.arrayTwo];
      ...
  
      return copy;
  }
  </code></pre>
  
  <p>So far this works just like I want it to, but when I try to sort the arrays of the copy, I get an error: 
      -[__NSArrayI sortUsingSelector:]: unrecognized selector sent to instance 0x100108a30</p>
  
  <p>I have noticed that the original arrays are of the type '_<em>NSArrayM' but the copy is '</em>_NSArrayI'... </p>
  
  <p>So what did I wrong? I have heard of deep copying using NSArchiver and NSUnarchiver... Do I have to use that? Sorry, I am quite new to C and Objective-C... :D</p>
  
  <p>I hope you can help me out of this. =)</p>
  
  <p>Sorry about my 'school-english'.... </p>
  
  <p>Cheers,
  Nick</p>
  
  <p>EDIT: The arrays consist of NSString objects, so I can use </p>
  
  <pre><code>sortUsingSelector:@selector(caseInsensitiveCompare:)
  </code></pre>
  
  <p>to sort the array.</p>