I am trying to use NSUserdefaults to save some data from a text field, I want it to be saved when the application quits and loaded when the application starts, however I have run into a wall.
The methods that I want to use are all in the AppDelegate, Now I do not understand how to use AppDelegate very well, I have thought of two possible ways to achieve this, I have no idea if it would work though.
- Import AppDelegate and over ride the methods inside my VC
OR - create an instance of my VC in AppDelegate and allow AppDelegate to set and retrieve the text of my UITextField – (Don’t this go against the MVC paradigm?)
Any suggestions would appreciated
Thank you very much for your time
As you mentioned above you have two options:
1-) Directly reach VC’s
UITextFieldfromAppDelegate‘sapplicationDidFinishLaunchingandapplicationWillTerminatemethods.On
applicationDidFinishLaunching:Read from
NSUserDefaults, setUITextFieldin VC.On
applicationWillTerminate:Read from
UITextFieldin VC, setNSUserDefaultsandsynchronize.2) Create proper methods in VC to do the same job and call them from
AppDelegate.