How to save state of the app when app terminates?
- by user164589
Hi guys.
I am trying to save the app state by encoding when the app terminates.
I've found the solution related this issue.
But I don't know how to use.
I am really trying to make encoding and decoding like this:
http://cocoaheads.byu.edu/wiki/nscoding
in CustomObject.h
@interface CustomObject : NSObject <NSCoding>
{
NSArray *someArray;
}
in CustomObject.m
@implementation CustomObject
// Other method implementations here
- (void) encodeWithCoder:(NSCoder*)encoder {
[encoder encodeObject:someArray forKey:@"someArray"];
}
- (id) initWithCoder:(NSCoder*)decoder {
if (self = [super init]) {
someArray = [[decoder decodeObjectForKey:@"someArray"] retain];
}
return self;
}
@end
My object to save is another NSArray. Not "someArray" in CustomObject. We call it that "MySaveObject".
I want to pass "MySaveObject" to "someArray" in CustomObject.
Actually I don't know how to encode "MySaveObject" and to pass to "someArray" in CustomObject.
Thanks in advance.