How can I add core data to a utility application
Pregunta
Ive made a simple ios utility application in xcode (version 4.4.1) but Ive realised that I need to store one integer in persistent memory. As far as I know using core data is the best way to achieve this. Ive added the core data framework to my app but I dont know the code that I need to add for it to work.
Could someone please help
Thanks
Solución
If you just need to store/retrieve an integer, NSUserDefaults
should be the way to go.
Saving
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
// saving an NSInteger
[prefs setInteger:42 forKey:@"integerKey"];
// This is suggested to synch prefs, but is not needed (I didn't put it in my tut)
[prefs synchronize];
Retrieving
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
// getting an NSInteger
NSInteger myInt = [prefs integerForKey:@"integerKey"];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow