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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:57:21+00:00 2026-06-08T08:57:21+00:00

I store time periods in Core Data. Each time period has an DateTime attribute

  • 0

I store time periods in Core Data. Each time period has an DateTime attribute called EndDate. I am trying to get the maximum end date, which is before (<) the date specified.

Financial period

This is how I have coded this using a subquery and ValueForKeyPath:

NSString *keyPath = [NSString stringWithFormat:@"SUBQUERY(SELF, $x, $x.EndDate < %@).@max.EndDate", date];
IBFinPeriod *periodBeforeCurrentDate = [self.finperiod valueForKeyPath:keyPath];

However, when running this code, I get the runtime error: the entity IBFinPeriod is not key value coding-compliant for the key "SUBQUERY(SELF, $x, $x".'

What is wrong with my code?
Do I need to specify the subquery differently?

Thank you for your help!!

  • 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-08T08:57:23+00:00Added an answer on June 8, 2026 at 8:57 am

    You could use a fetch request with fetchLimit set to 1 and a descending sort descriptor.

    If you insist on the valueForKeyPath: I would first filter the results with filteredArrayUsingPredicate: (with a straight forward predicate selecting the records with dates prior to your date) and then simply using @"@max.EndDate" as the key path.

    If you need the entire object rather than just the date, just sort your set:

    NSSet *periodsBeforeCurrentDate = [self.finperiod 
        filteredSetUsingPredicate:[NSPredicate predicateWithFormat:
           @"EndDate < %@", date]];
    if (periodsBeforeCurrentDate.count) {
        *sort = [NSSortDescriptor sortDescriptorWithKey:@"EndDate" ascending:NO];
       NSArray *sortDescriptors = [NSArray arrayWithObject:sort];
       IBFinPeriod *lastPeriodBeforeCurrentDate =[[periodsBeforeCurrentDate 
           sortedArrayUsingDescriptors:sortDescriptors] objectAtIndex:0];
    }
    

    In my opinion it would be easier to just fetch.

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

Sidebar

Related Questions

Using MySQL should I store time data as an Int which would be the
Is there a way that I can store variables for long periods of time?
I need to store a set of data structures that are defined by period
I need to store a user's password for a short period of time in
The site is about special discount events. Each event contains a period of time
I want to store some values only for certain period of time in a
Is it possibile to store time per point with millisecond precision? Since Graphite is
When I need to store time/date information, how is it best to be stored
I need to store a time offset in a database column (for example, 12:25
following How to store date/time and timestamps in UTC time zone with JPA and

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.