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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:25:14+00:00 2026-06-18T06:25:14+00:00

I have a simple counter application, i.e. the user presses a button to increase

  • 0

I have a simple counter application, i.e. the user presses a button to increase it by a value of their choice. I started the application production on a single view application. I now have the need to make it so that when the app is closed it saves the last value of the counter. Then when the app reopens it needs to load the value of the counter back into place. The value needs to be saved and reloaded simply by closing and opening the app i.e. no buttons are needed to be pressed.

My counter variable is an Int value called counter. The view controllers are simply named viewController.h/m.

I have no idea how to set all of this up, I assume I need coreData to do this. How do I set up coreData? Do I code in my delegate of viewController? If this is not the best way to do it please provide a way to do it in a more effective way!

Thanks very much for any help, simple instructions appreciated most of all.
I have had a look at other example of this but none seemed to provide what I need or were simple enough to understand. Please provide an answer on this thread!

Hugh

  • 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-18T06:25:16+00:00Added an answer on June 18, 2026 at 6:25 am

    It’s easiest to simply use NSUserDefaults instead of Core Data.

    To save:

    [[NSUserDefaults standardUserDefaults] setInteger:counter forKey:@"counter"]
    

    To read:

    NSInteger counter = [[NSUserDefaults standardUserDefaults] integerForKey:@"counter"];
    

    Take a look at UIApplicationDelegate to find what methods you should place the code in. It will likely be in your AppDelegate in one of the following methods:

    Where to load the value:

    • -application:didFinishLaunchingWithOptions:
    • –applicationWillEnterForeground:

    Where to save the value:

    • -applicationDidEnterBackground:
    • –applicationWillTerminate:

    Exactly where depends on if you need to load and save the value when the user switches to another app, which is almost certainly the case as the app might be terminated when it is in a frozen state due to memory pressure. In this case you would want to make sure the value was saved when the app was backgrounded (the user switched to a different app) and the value was restored when the app became the foreground app (the user switched back to your app).

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

Sidebar

Related Questions

I have a really simple Rails application that allows users to register their attendance
I have a simple application where a user clicks on an area, and the
I have a simple test application: Model: public class Counter { public int Count
I have a simple django page that has a counter on it. I use
I have the following simple script. However, it incorrectly gives the counter result to
I have an application in WPF which constantly changes the value(Updates!) in the GUI
I am developing a simple WinAPI application and started from writing my own assertion
I'm creating a simple click counter android app, sound is played when a button
Good day to everybody I have a simple counter php+db it checks ref number
We have a simple AJAX application that pings a web service and populates an

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.