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

  • Home
  • SEARCH
  • 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 8827537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:23:41+00:00 2026-06-14T07:23:41+00:00

I have an NSArray of NewsArticle objects: @interface NewsArticle : NSObject @property (nonatomic, strong)

  • 0

I have an NSArray of NewsArticle objects:

@interface NewsArticle : NSObject

@property (nonatomic, strong) NSString *title;
@property (nonatomic, strong) NSDate *dateTime;
@property (nonatomic, strong) NSString *content;

@end

And I want to create an NSArray of the unique dates (ignoring time) stored within each article.dateTime – I know I can do this the long way around by enumerating the array and doing the checking myself, but I’m hoping for a simpler solution.

I’m from a C# background and I know in C# I could do this with a simple LINQ statement – it would seem that NSPredicate might offer this functionality, but I can’t work out how, or find any suitable examples online.

  • 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-14T07:23:42+00:00Added an answer on June 14, 2026 at 7:23 am

    NSPredicate is designed for filtering a collection of objects, but you want to extract a property from each member of the collection.

    You can (as CAMOBAP said in his comment) use key-value coding (KVC) to get an array of all the dateTime values. Then you can use an NSSet to eliminate the duplicates:

    NSArray *allDateTimes = [articles valueForKey:@"dateTime"];
    NSSet *uniqueDateTimes = [NSSet setWithArray:allDateTimes];
    

    You can even do it all in one KVC message, using the somewhat esoteric @distinctUnionOfObjects key:

    NSArray *uniqueDateTimes = [articles valueForKeyPath:@"@distinctUnionOfObjects.dateTime"];
    

    Note that this second example uses valueForKeyPath:, not valueForKey:.

    You can learn more (oh so much more!) by reading the Key-Value Coding Programming Guide.

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

Sidebar

Related Questions

i have an NSArray which contains custom objects, the objects have an NSString property,
I have an NSArray of NSDate objects and I want to sort them so
I have an NSArray of objects, which have a property id . I then
I have an NSArray containing numbers as NSString objects. ie. [array addObject:[NSString stringWithFormat:@%d, 100]];
I have an NSArray of objects: MyObject consists of the following string properties: Title
I have an NSArray of objects , which has a particular property called name
I have an NSArray of double objects.... I currently I have a for loop
I have an NSArray of (Product) objects that are created by parsing an XML
I have an NSArray of NSDictionary objects which I would like to be able
So I have an NSArray with custom objects called Church. And in each church

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.