Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8663651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:02:24+00:00 2026-06-12T17:02:24+00:00

I have a class, say the class Person. In than class I have several

  • 0

I have a class, say the class Person. In than class I have several NSMutableArrays.

@property NSMutableArray *arrayOne;
@property NSMutableArray *arrayTwo;
...

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.

To do that I have implemented this in my Person.m:

-(id)copyWithZone:(NSZone *)zone
{
    Person *copy = [[Person allocWithZone:zone] init;
    copy.arrayOne = [NSMutableArray arrayWithArray:self.arrayOne];
    copy.arrayTwo = [NSMutableArray arrayWithArray:self.arrayTwo];
    ...

    return copy;
}

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

I have noticed that the original arrays are of the type ‘_NSArrayM’ but the copy is ‘_NSArrayI’…

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… 😀

I hope you can help me out of this. =)

Sorry about my ‘school-english’….

Cheers,
Nick

EDIT: The arrays consist of NSString objects, so I can use

sortUsingSelector:@selector(caseInsensitiveCompare:)

to sort the array.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:02:25+00:00Added an answer on June 12, 2026 at 5:02 pm

    How are your mutable array properties being declared in your header file?

    // Wrong
    @property (copy) NSMutableArray *array;
    @property (assign) NSMutableArray *array;
    
    // Right
    @property (strong) NSMutableArray *array;
    

    NB If you’re just doing

    @property NSMutableArray *array;
    

    then I’m amazed your code has got this far 🙂 The default property memory semantics is assign – which won’t tell ARC to retain your arrays in any way at all 🙂 You need to specify strong.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a class which represents a person, a variable within that class
Say I have a method, and within that method it instantiates a Person class:
Simple question I have a class say person who has as a property a
Let's say I have a grails domain class that looks like class Person {
Say I have my class @interface Person : NSObject { NSString *name; } I
Let's say I have a Person class and an Order class, with foreign keys
Let's say we have a collection of Person objects class Person { public string
Let's say I have this entity (for Hibernate): @Entity public class Person { @Id
So let's say you have something like this: Class Person: height = 6' 0
Say you have a class Person (with name, age, etc), and an array called

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.