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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:01:34+00:00 2026-05-31T16:01:34+00:00

I have a couple of views which present data from a CoreData entity in

  • 0

I have a couple of views which present data from a CoreData entity in my app. To retrieve the data required for the views I often have to implement multiple fetchRequests which feels wrong – perhaps I’m still making basic mistakes like thinking of CoreData in too much of a SQL database sense.

In fact for one of my views I have 22 fetch requests which may well be the correct way of achieving what I need but as an iPhone/Objective-C novice I can’t help questioning my approach. Here is a snippet of my code showing 2 of many fetchRequest, could you give me a nudge in the right direction if I am doing it wrong?

      SGK_T4T_01AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    NSManagedObjectContext *context = [appDelegate managedObjectContext];
    NSEntityDescription *entityDiscription = [NSEntityDescription entityForName:@"Sessions" inManagedObjectContext:context];

//Swim 3 Count
        NSFetchRequest *request2 = [[NSFetchRequest alloc] init];
        [request2 setEntity:entityDiscription];
        [request2 setResultType:NSDictionaryResultType];
        NSExpression *keyPathExpression2 = [NSExpression expressionForKeyPath:@"sport"];
        NSExpression *swimCountExpression = [NSExpression expressionForFunction:@"count:" arguments:[NSArray arrayWithObject:keyPathExpression2]];
        NSExpressionDescription *expressionDescription2 = [[NSExpressionDescription alloc] init];
        [expressionDescription2 setName:@"swimCount"];
        [expressionDescription2 setExpression:swimCountExpression];
        [expressionDescription2 setExpressionResultType:NSInteger16AttributeType];
        [request2 setPropertiesToFetch:[NSArray arrayWithObject:expressionDescription2]];
        NSPredicate *pred2 = [NSPredicate predicateWithFormat:@"(date >= %@ AND sport like %@)", swimSinceDateAsDate, sportTypeSwim];
        [request2 setPredicate:pred2];

        NSError *error2;
        NSArray *objects2 = [context executeFetchRequest:request2 error:&error2];
        if (objects2 == nil) {
            NSLog(@"The fetch request returned an array == nil");
        } else {
            _swimTotalSwimCountLabel.text = [[NSString alloc] initWithFormat:@"%@", [[objects2 objectAtIndex:0] valueForKey:@"swimCount"]];
        }

        //Swim 4 Fastest 1500m Time Trial
        NSFetchRequest *request3 = [[NSFetchRequest alloc] init];
        [request3 setEntity:entityDiscription];
        [request3 setResultType:NSDictionaryResultType];
        NSExpression *keyPathExpression3 = [NSExpression expressionForKeyPath:@"time1"];
        NSExpression *swimfastest1500Expression = [NSExpression expressionForFunction:@"min:" arguments:[NSArray arrayWithObject:keyPathExpression3]];
        NSExpressionDescription *expressionDescription3 = [[NSExpressionDescription alloc] init];
        [expressionDescription3 setName:@"swimFastest1500"];
        [expressionDescription3 setExpression:swimfastest1500Expression];
        [expressionDescription3 setExpressionResultType:NSInteger16AttributeType];
        [request3 setPropertiesToFetch:[NSArray arrayWithObject:expressionDescription3]];
        NSString *sessType3 = @"Time Trial - 1500m";
        NSPredicate *pred3 = [NSPredicate predicateWithFormat:@"(date >= %@ AND sport like %@ AND sessiontype like %@)", swimSinceDateAsDate, sportTypeSwim, sessType3];
        [request3 setPredicate:pred3];

        NSError *error3;
        NSArray *objects3 = [context executeFetchRequest:request3 error:&error3];
        if (objects3 == nil) {
            NSLog(@"The fetch request returned an array == nil");
        } else {
            NSUInteger durationInSeconds = [[[objects3 objectAtIndex:0] valueForKey:@"swimFastest1500"] integerValue];
            NSUInteger durationInMinutes = durationInSeconds / 60;
            NSUInteger durationRemainder = durationInSeconds % 60;
            _swimTt1500PaceLabel.text = [[NSString alloc] initWithFormat:@"%02i:%02i", durationInMinutes, durationRemainder];
        }

Thanks in advance for any assistance, links or direction you may be able to provide…

  • 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-31T16:01:35+00:00Added an answer on May 31, 2026 at 4:01 pm

    The predicate stuff doesn’t look too bad – but may I ask why you’re limiting to all those NSExpressionDescriptions? Did you analyze and find that by limiting to just those properties you found concrete performance improvements? Core Data is usually pretty good at faulting/optimizing your memory, and that might clean up the statements quite a bit.

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

Sidebar

Related Questions

Here's the problem: I have couple of pages which gets its content from a
I have a couple of views which are rendering the same template and I
I have an application which has a couple of UITextField present to allow my
I have a list view which has a couple of views within it, I
I have a couple of views which use the SELECT CASE syntax.However when I
I have an application with many views. I want only a couple of the
I'll have couple of python functions I must interface with from the assembly code.
SETUP : I have this app which has 4 activities in a linear path,
In my application I have a tableview which a couple of cells on click
I have a horizontal linear layout with an image and a couple text views.

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.