0

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.

Ferdinand
  • 1,193
  • 4
  • 23
  • 43

1 Answers1

0

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 king
  • 112,709
  • 45
  • 203
  • 241