The easiest way is to use NSUserDefaults . Here you can store any structure of their simple data (numbers, strings, collections, dates, NSDate).
- (void)save { [[NSUserDefaults standardUserDefaults] setObject:@{@"x" : @(self.x), @"y" : @(self.y)} forKey:@"WarKey"]; [[NSUserDefaults standardUserDefaults] synchronize]; } - (void)load { NSDictionary *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"WarKey"]; if (data == nil) { self.x = DEFAULT_X; self.y = DEFAULT_Y; } else { self.x = [data[@"x"] intValue]; self.y = [data[@"y"] intValue]; } }
You need to call save before swearing an application, but it is better to do it more often, whenever possible — whenever you change the data, since when the application is crashed, the will terminate will not be called on an error. Well load - respectively, at the start of the application.
Update
He can write a set of fields, or, for example, a json string. This method is not deprecated. Its disadvantage is that the object (in our case, the dictionary with the data of the War object) is stored in it in one piece of data and you have to rewrite the entire object to overwrite it. The content of user defaults in terms of privacy is equal to the Documents folder, if I'm not mistaken, you can even sync it through cloud. Of course, it is more correct to do it through CoreData, but it all depends on the complexity and amount of data. If uh is 10-20 fields - then defaults will be an excellent and convenient alternative to CoreData.