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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:27:52+00:00 2026-05-29T13:27:52+00:00

I am currently coding an app which calls a text file from a store,

  • 0

I am currently coding an app which calls a text file from a store, displays it and then increments so that the next file can be loaded when needed. I have got the base code to work by the use of a button click however I want it to be able to call the text file only when 24 hours has past since the last one was loaded effectively making it update every day.

I am trying to do this by using NSDate and NSUserDefaults to store the previous time that a file was called and then compare it to the current time, if it has been more than 24 hours increment and call the next.

However after trying to add things and change around the base code below I just cannot work out how to get it to work. I don’t know if this is just because I have not had enough experience and don’t know the language well enough or if I am just being a bit silly and missing something really simple.

Any help would be greatly appreciated.

NSDate *nowDate = [NSDate date];
[[NSUserDefaults standardUserDefaults] setObject:nowDate forKey:@"LastLoaded"];

NSDate *lastLoaded  = [[NSUserDefaults standardUserDefaults] objectForKey:@"LastLoaded"];

NSDate *checkDate = [NSDate dateWithTimeIntervalSinceNow:-24*60*60];
if([lastLoaded compare:checkDate] == NSOrderedAscending) {
    static int number = 1;
    NSString *filePath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%i",number++] ofType:@"txt"];
    if (filePath) {
        NSString *textFromFile = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
        if (textFromFile) {
            textView.text = textFromFile;
        }
    }
}
  • 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-29T13:27:53+00:00Added an answer on May 29, 2026 at 1:27 pm

    There is a bug in your code. You are not retrieving the last update date from NSUserDefaults. You are retrieving the current date, as you are overwriting the LastUpdatedate with current date in the very second line of code.

    //NSDate *nowDate = [NSDate date];
    //[[NSUserDefaults standardUserDefaults] setObject:nowDate forKey:@"LastLoaded"];
    
    NSDate *lastLoaded  = [[NSUserDefaults standardUserDefaults] objectForKey:@"LastLoaded"];
    
    //NSDate *checkDate = [NSDate dateWithTimeIntervalSinceNow:-24*60*60];
    if ([lastLoaded timeIntervalSinceNow] < -24*60*60 ){
    //Now you can update the NSUserDefaults
    [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:@"LastLoaded"];
    //if([lastLoaded compare:checkDate] == NSOrderedAscending) {
    static int number = 1;
    NSString *filePath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%i",number++] ofType:@"txt"];
    if (filePath) {
        NSString *textFromFile = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
        if (textFromFile) {
            textView.text = textFromFile;
        }
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently coding an Android app, which will be used to count Traffic
I am currently coding a simple Data Access Layer, and I was wondering which
I am coding a data intense web app. So that means I cant be
I currently have an iOS app that allows people to submit content to our
I am writing an iPhone app which gets data from a mysql database. I
I have an IPhone app that uses webservices to get data from a server.
I'm currently coding an iPhone app and i need to simulate a HTML select.
I'm currently planning (and part coding) a new app. I have an array of
I am writing a Webkit app that imports data from an RSS feed and
I am currently coding a website for a band and i have a music

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.