I am relatively new to Objective-C and Cocoa and have built an application in which I want to be able to save the current data. (AS in File - Save As - countDown.cd or somthing) After the save you could then Open the saved file and it would restore the app with the appropriate data etc... What is the best way of doing this? I know I can obviously make a text file with the stored data in key pairs and then parse on an open but is there a better/more standard approach. Thanks.
You probably want to look at NSArchiver, NSCoder, and related classes. This document has a lot more info on it.
If you're going to go down this route, use NSKeyedArchiver since it is better for backwards compatibility for future versions of your app.
Ok so I checked it out and I thought I got it to work but I have a problem. Does anyone have an idea why this doesn't update my NSDatePicker when I load the saved file? Code: - (NSData *)dataRepresentationOfType:(NSString *)aType { NSDate* date = [datePicker dateValue]; return [NSKeyedArchiver archivedDataWithRootObject: date]; } - (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType { NSLog(@"About to read data of type %@", aType); NSDate* date; date = [NSKeyedUnarchiver unarchiveObjectWithData:data]; if(date == nil){ NSLog(@"Test"); return NO; } else{ [datePicker setDateValue: date]; return YES; } return YES; }