How to save state of the app when app terminates?
Posted
by user164589
on Stack Overflow
See other posts from Stack Overflow
or by user164589
Published on 2010-04-28T10:30:43Z
Indexed on
2010/04/28
10:33 UTC
Read the original article
Hit count: 212
iphone
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.
© Stack Overflow or respective owner