Store a value beyond applicationWillTerminate

I have searched in Apple’s iOS dev center but couldn’t find anything quite right. Here’s my problem:

I have an app that uses CoreData with several entities. The data is dynamically updated via a server. Now checkForUpdates is called every time the app becomes active, but is only executed when a certain amount of time passed since the last update.

  • Apple Watch App Fails Submission Invalid Info.plist and Icon
  • Print appended struct (swift4)
  • Image asset size in Xcode interface builder
  • “Pushing the same view controller instance more than once is not supported” exception
  • Swift 2.2 #selector in protocol extension compiler error
  • When is didRegisterForRemoteNotificationsWithDeviceToken called?
  • When checkForUpdates is finally executed it updates all the content, checking for each object if the version on the server is a more recent one according to the last time an update was done.

    I have a local variable in my Updater class of type NSDate that holds the last time an update was successfully done. I need to be able to store this value somehow and somewhere beyond termination of the application.

    I was wondering what would be the most cost-effective way memory-wise and also in terms of performance. Looking at the iOS dev center I first thought about application preferences, but since it is only a single value I thought there would be an easier way. Sorry if this is really easy but I’m new to objective-c and iOS programming.

    Any help would be appreciated! If more information is needed feel free to comment below.

    edit: Would it be a good idea to simply create a new entitiy with an NSDate attribute and to simply keep the lastUpdateTime variable in my database?

    Best regards,
    Octoshape

    3 Solutions Collect From Internet About “Store a value beyond applicationWillTerminate”

    Sounds like you want the NSUserDefaults storage. It’s used like a dictionary, but persists:

    [[NSUserDefaults standardUserDefaults] setObject:myDate forKey:@"LastUpdateTime"];
    

    Use NSUserDefaults to store the last update time.

    When your Updater is successful, write the success time to your apps defaults, that way it is accessible on your next launch, and you can call this anytime you to.

    Swift 2.X Version

    NSUserDefaults.standardUserDefaults().setObject(NSDate(), forKey: "Last_Modified")