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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:51:21+00:00 2026-05-25T12:51:21+00:00

I have 2 entities: Performance.start (NSDate) Location.coordinates Performance.end (NSDate) Location.name_extern Performance.location <<–> Location.performances I

  • 0

I have 2 entities:

Performance.start (NSDate)    Location.coordinates
Performance.end   (NSDate)    Location.name_extern
Performance.location   <<-->  Location.performances

I have a NSFetchedResultsController for my UITableView set up with the following code:

[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest 
                                    managedObjectContext:self.managedObjectContext 
                                      sectionNameKeyPath:@"location.name_extern" 
                                               cacheName:nil];

So the data is divided into sections by locations (their names).

Now I have a variable selectedTime of type NSDate and want to fetch (with a single fetch if possible) the following:

  1. Only 2 Performances per Location:
    • The Performance that is running (selectedTime BETWEEN {start, end})
    • The Performance that will start after the one that is running at the selected time

I’m really lost here :-/ Even if you could just give me the SQL statement for such a fetch/query I would at least know which direction to head..

  • 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-25T12:51:21+00:00Added an answer on May 25, 2026 at 12:51 pm

    Duh.. I think I found the final solution ..

    The fetch is pretty simple:

    NSEntityDescription *entity = [NSEntityDescription 
                                   entityForName:@"Performance" inManagedObjectContext:self.managedObjectContext];
    [fetchRequest setEntity:entity];
    
    NSSortDescriptor *sort1 = [[NSSortDescriptor alloc] 
                              initWithKey:@"location.name_extern" ascending:YES];
    NSSortDescriptor *sort2 = [[NSSortDescriptor alloc] 
                               initWithKey:@"start" ascending:YES];
    [fetchRequest setSortDescriptors:[NSArray arrayWithObjects:sort1,sort2,nil]];
    
    [fetchRequest setFetchBatchSize:20];
    
    NSFetchedResultsController *theFetchedResultsController = 
    [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest 
                                        managedObjectContext:self.managedObjectContext 
                                          sectionNameKeyPath:@"location.name_extern" 
                                                   cacheName:nil];
    

    With the following predicate:

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"end > %@",selectedTime];
    
    [fetchRequest setPredicate:predicate];
    

    And here’s how I solved the “only 2 per location/section” part:

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
        if (selectedTime == nil)
        {
            return [sectionInfo numberOfObjects];
        }
        else
        {
            if ([sectionInfo numberOfObjects] > 2)
            {
                return 2;
            }
            else
            {
                return [sectionInfo numberOfObjects];
            }
        }
    }
    

    Thanks for trying though André!

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

Sidebar

Related Questions

If I have entities set up for Parent - Child - Grandchild and one
I have three entities: Country, State and City with the following relationships: When creating
Imagine we have a set of entities each of which has its state: free,
I have the following entities: Event and Attribute. An event can have many attributes.
I have entities similar to: ProductLine: id, name ProductLineContents: content_id, product_line_id Content: id, text,
I'm working on a web application. I have entities that are supposed to be
I am using Entity Framework and DevExpress 10.5 XtraGrid. Imagine that we have entities
I have two entities: Recipe and Ingredient. Entites: public class Ingredient { public int
I have two entities A and B. public class A{ @Id @GeneratedValue private Integer
I have 2 entities in CoreData (which are relevant to this). Let's call them

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.