tags:

views:

89

answers:

2

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.

+1  A: 

See if this tutorial helps...

ohho
Thanks, But I need to encode data when save it.
http://stackoverflow.com/questions/537044/storing-custom-objects-in-an-nsmutablearray-in-nsuserdefaults
ohho
Thanks. But it is not issue I am searching. My main point is how to pass MySaveObject" to "someArray" in CustomObject by encoding.
A: 

You have to make sure that the objects contained in the array are also able to be encoded. If those objects are custom objects, you'll have to implement NSCoding in them yourself.

nevan