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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:33:20+00:00 2026-06-17T21:33:20+00:00

I have filled a NSMutableArray with integer and string values from my database. The

  • 0

I have filled a NSMutableArray with integer and string values from my database.
The problem is that many values were inserted more than once.
Using the following code I remove duplicate objects

for (id object in originalArray) {
    if (![singleArray containsObject:object]) {
        [singleArray addObject:object];
    }
}

Bus this works only if the objects are exactly the same between them.
Is there a way to remove duplicates based on the integer value?

EDIT (from an OP’s comment on a deleted answer)

I have some objects containing int and NSString. For example @"John 13", @"Mary 25", @"Luke 25", @"Joan 13". The NSMutableArray will contain all four names and duplicates of 13, 25. I want to remove the duplicates leaving 13 and 25 only once in the array. I do not care which names will be removed. Care only for the integer values to use them later.

  • 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-17T21:33:21+00:00Added an answer on June 17, 2026 at 9:33 pm

    If your elements are all NSNumber objects:

    for (int i=0;i<array.count;i++) {
        for (int j=i+1;j<array.count;j++) {
            if ([array[i] isEqualToNumber:array[j]]) {
               [array removeObjectAtIndex:j--];
            }
        }
    }
    

    Or if all objects are either integer NSNumbers or NSStrings containing integer values:

    for (int i=0;i<array.count;i++) {
        for (int j=i+1;j<array.count;j++) {
            if ([array[i] intValue] == [array[j] intValue]) {
               [array removeObjectAtIndex:j--];
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an MutableArray filled with values from a database: NSMutableArray *objectsArray = [[NSMutableArray
I have a datagrid that I have filled with data from a sql database.
In my app I have a tableview being filled by values from an NSMutableArray.
I have a text field In that user can enter values from 1-10 at
I have an NSMutableArray filled with BeziarPaths. I'd like to serialize it so that
I have a NSMutableArray filled with NSMutableArray's. I would like to fill my table
So I have an NSMutableArray in my app what is filled like so: NSMutableArray
I have filled List<Object1> Object 1 contain 2 fields (int id & string name)
I have ArrayProxy filled with different values, and after tossing it in iterator and
I've created an app which contains form and that have to filled up in

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.