I need to save my objects in permanent memory. The option I use right now is that i save my objects in the NSUserDefaults before my app quits and I retrieve them when my app starts running. This approach is not very convenient since I may lose important data in case the application crashes. Is there any way to store my objects, but when a property of an object changes, then this change is saved in the disk automatically? Except for that, there is a danger to mess the objects in ram and the objects in the disk using that architecture.
For example
-> Load objects from memory
-> [object1 setValue:@"5"]
-> Application crashes
After the crash, when the user opens the application, the value @”5″ will not be available because I never saved the data.
Is there any alternative so as to make by code more safe and maintainable? CoreData is a good option for this problem , or is it an overhead?
It is really not the best of option to save data instantly when a value changes. It’s way too expensive for app performance. You must continue using
NSUserDefaultsto store the values when app is force closed or entered in background.Your app is designed by you. It MUST not crash but even if it does, don’t worry. Anamolies cannot really be handled.