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 7502521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:54:02+00:00 2026-05-29T20:54:02+00:00

How do you compare 2 NSMutableArray ? Different people might say this is a

  • 0

How do you compare 2 NSMutableArray ?

Different people might say this is a duplicate question, but i haven’t found a solution to my problem after viewing most of the SO question.

There is a Person object, and it has the Fields Name, Age, Rank

I have a MutableArray which will save the data from NSUserDefaults. then it will see if the NSMutableArray is contains that particular object. if not it will add it to NSUserDefaults.

There is some problem when i am adding the person object to NSUserDefaults (I am adding the person object through an array, see code).

When i print [data count] it is always 0. So it might not be getting added to NSUserDefaults properly. Or i might be doing some mistake.

NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];

            if (userDefaults ) {

                NSArray *arr= [userDefaults objectForKey:@"person"];

                data = [NSMutableArray arrayWithArray:arr];

NSLog (@"%i ", [data count]);

                if (! [data containsObject:self.person] ) {

                    [data addObject:self.person];

                    NSArray *personarr= [NSArray arrayWithArray:data];

                    [userDefaults setObject:personarr forKey:@"person"];

                    [userDefaults synchronize];
  • 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-05-29T20:54:04+00:00Added an answer on May 29, 2026 at 8:54 pm

    If you get an array from NSUserDefaults, it will never be the same pointer, as any current object (like self.person).. so this won’t ever work. Comparing objects with == compares their memory adresses.

    If you want to compare them, use their contents. (eg. [[person objectForKey: @"Name"] isEqualToString: [person2 objectForKey: @"Name"]]). So you should do it in a loop and check, if the name of the new person is already existing.

    Also, arrayWithArray is NOT a initializer of NSMutableArray.
    So if it should be mutable, do it like that:

    NSArray *arr= [userDefaults objectForKey:@"person"];
    data = [[arr mutableCopy] autorelease];
    

    And if your count is always zero, check the actual array contents and look whats inside.
    E.g. like this:

    NSArray *arr= [userDefaults objectForKey:@"person"];
    CFShow(arr);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with counting numbers of object in nsmutablearray. I have this
I just wanted to compare different solutions used when implementing ACLs in Rails.
I've heard that it is a bad idea to do something like this. But
I have two NSMutableArray filled with data object. how do I compare both array
Compare this http://jsfiddle.net/AndyMP/tbYsM/1/ which works with this http://jsfiddle.net/AndyMP/tbYsM/2/ which doesn't. The first is just
I am playing around with this tutorial I found on a website. It is
How can I compare two NSMutableArray ? if both are same than it should
I am confused about strings (a beginner's problem, I'm afraid): I have one NSMutableArray
I am trying to create this method. Let's call this -(NSMutableArray*) getEightClosestSwatchesFor:(CGFloat)hue { NSString
So this is a rather basic question regarding the best way to sort an

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.