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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:19:19+00:00 2026-05-26T23:19:19+00:00

I’m writing an app that displays some data which changes based upon the day

  • 0

I’m writing an app that displays some data which changes based upon the day of the week it is. The context of the app is that it is for a conference that is upcoming. I want to display the calendar entries for that day. The event detail being stored in coredata.

What I’m using to create the NSPredicate is:

NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-dd"];
NSDate *today = [NSDate date];
NSString *sunday = @"2011-12-04";
NSString *monday = @"2011-12-05";
NSString *tuesday = @"2011-12-06";
NSString *wednesday = @"2011-12-07";
NSInteger dayNumber = 1;

if ([[df stringFromDate:today] isEqualToString:sunday]) {
    dayNumber = 2;
} else if ([[df stringFromDate:today] isEqualToString:monday]) {
    dayNumber = 3;
} else if ([[df stringFromDate:today] isEqualToString:tuesday]) {
    dayNumber = 4;
} else if ([[df stringFromDate:today] isEqualToString:wednesday]) {
    dayNumber = 5;
}

NSExpression *lhs = [NSExpression expressionForKeyPath:@"day_number"];
NSExpression *rhs = [NSExpression expressionForConstantValue:[NSNumber numberWithInt:dayNumber]];

NSPredicate *equalToPredicat = [NSComparisonPredicate predicateWithLeftExpression:lhs
                                                                  rightExpression:rhs
                                                                         modifier:NSDirectPredicateModifier
                                                                             type:NSEqualToPredicateOperatorType
                                                                          options:0];

// Edit the sort key as appropriate.
NSSortDescriptor *sortDescriptorTime = [[NSSortDescriptor alloc] initWithKey:@"start_time" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:/*sortDescriptorDayNumber,*/ sortDescriptorTime, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
[fetchRequest setPredicate:equalToPredicat];

NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest 
                                                                                            managedObjectContext:managedObjectContext 
                                                                                              sectionNameKeyPath:@"day_number" 
                                                                                                       cacheName:@"TodayCache"]

What I am seeing though is that when the date changes (ie: Saturday to Sunday) the data (displayed in a UITableView) doesn’t get updated.

Thanks,
Matt.

  • 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-26T23:19:20+00:00Added an answer on May 26, 2026 at 11:19 pm

    The comment above is correct. Some more info.

    1) The table will only update when [tableView reloadData] or one of the other reload methods is called

    2) If you set a delegate for the NSFetchedResultsController you can respond to model changes and reload the table

    3) The date changing is not a model change (unless you are updating the date in the model itself) and the NSFetchedResultsController will only update itself if it detects that it’s managed object context has changed.

    4) You need to do fetchedResultsController:performFetch:error when when the day changes b/c you are changing the predicate (i.e. the request). Otherwise, the table will reload with the old data.

    To refresh the table based on the date changing, you need to detect the date change at whatever interval you like and reload the table at that time. One way you could do it is to calculate the interval between the current time and midnight and set a timer to fire after that interval. When the timer fires, change the predicate, performFetch with the results controller and reload the table. Then set a new timer until the next midnight. If you want this to be done in the users time zone, you’ll need to take that into account also.

    EDIT: clarified answer that a performFetch is necessary when the predicate changes

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am writing an app with both english and french support. The app requests
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace

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.