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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:32:20+00:00 2026-06-14T23:32:20+00:00

Suppose I have a class Event, and it has 2 properties: action (NSString) and

  • 0

Suppose I have a class Event, and it has 2 properties: action (NSString) and date (NSDate).

And suppose I have an array of Event objects. The problem is that “date” properties can match.

I need to remove the duplicates, meaning that 2 different objects with the same date IS a duplicate.

I can remove duplicates in any array of strings or nsdates, they are easy to compare. But how to do it with complex objects, where their properties are to be compared?

Don’t ask me what I did so far, cos’ the only thing coming in my mind is a bubble sort, but it’s a newbie solution, and slow.

Quite any help is highly appreciated (links, tuts, code).

Thanks in advance.

EDIT

Thanks to dasblinkenlight, I have made a custom method:

- (NSArray *)removeDuplicatesInArray:(NSArray*)arrayToFilter{

    NSMutableSet *seenDates = [NSMutableSet set];
    NSPredicate *dupDatesPred = [NSPredicate predicateWithBlock: ^BOOL(id obj, NSDictionary *bind) {
        YourClass *e = (YourClass*)obj;
        BOOL seen = [seenDates containsObject:e.propertyName];
        if (!seen) {
            [seenDates addObject:e.when];
        }
        return !seen;
    }];
    return [arrayToFilter filteredArrayUsingPredicate:dupDatesPred];
} 

Here YourClass is the name of your class the object belongs to, and propertyName is the property of that object you are going to compare.

Suppose self.arrayWithObjects contains the objects of YourClass.

After populating it, use

self.arrayWithObjects = [self removeDuplicatesInArray:self.arrayWithObjects];

and you are done.

All credits to dasblinkenlight.
Cheers!

  • 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-14T23:32:22+00:00Added an answer on June 14, 2026 at 11:32 pm

    You can create an NSMutableSet of dates, iterate your event list, and add only events the date for which you have not encountered before.

    NSMutableSet *seenDates = [NSMutableSet set];
    NSPredicate *dupDatesPred = [NSPredicate predicateWithBlock: ^BOOL(id obj, NSDictionary *bind) {
        Event *e = (Event*)obj;
        BOOL seen = [seenDates containsObject:e.date];
        if (!seen) {
            [seenDates addObject:e.date];
        }
        return !seen;
    }];
    NSArray *events = ... // This is your array which needs to be filtered
    NSArray *filtered = [events filteredArrayUsingPredicate:dupDatesPred];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose that I have two classes, first a class without any properties, fields or
Suppose I have an event KeyPress subscribed to by various classes. Assume that Class
Suppose I have a class Baz that inherits from classes Foo and Bar ,
Suppose I have some class which has a property actor_ of type Actor .
Suppose I have a class that processes some data: class SomeClass { public: void
Suppose I have a class T where T has no virtual functions. T instances
suppose i have small wcf service which has duplex connection and i want that
Suppose I have these two objects: public class Object1 { string prop1; string prop2;
Suppose I have class Foo(db.Model): bar = db.ReferenceProperty(Bar) foo = Foo.all().get() Is there a
Suppose I have: class Foo { ... }; class Bar : public Foo {

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.