I am trying to convert MailDemo application to cocoa-Document based application, from scratch, and implemented the following two methods, as suggested by Apple documentation:
// Write data to a file when save is selected
- (NSData *)dataOfType
NSString *)typeName error
NSError **)outError
{
// Make sure we have data to save, and not just an empty document.
NSLog(@"mailboxes desctiption: %@ items.\n", self.mailboxes);
return [NSKeyedArchiver archivedDataWithRootObject:[self mailboxes]] ;
}
read data from a file, when Open is selected
- (BOOL)readFromData
NSData *)data ofType
NSString *)typeName error
NSError **)outError
{
self.mailboxes = [NSKeyedUnarchiver unarchiveObjectWithData:data];
NSLog(@"mailboxes desctiption: %@ items.\n", self.mailboxes);
return YES;
}
- (id) initWithCoder: (NSCoder *)coder
{
if (self = [super init])
{
[self setProperties: [coder decodeObjectForKey
"properties"]];
[self setEmails: [coder decodeObjectForKey
"emails"]];
}
return self;
}
- (void) encodeWithCoder: (NSCoder *)coder
{
[coder encodeObject: properties forKey
"properties"];
[coder encodeObject: emails forKey
"emails"];
}
and similar one for emails.
Everything seems fine to me, except that I can save but cannot restore the data. I can see that mailboxes array has values when trying to read from a file.
Any idea what may be happening? Thank you all great folks for your help.
KP
// Write data to a file when save is selected
- (NSData *)dataOfType
{
// Make sure we have data to save, and not just an empty document.
NSLog(@"mailboxes desctiption: %@ items.\n", self.mailboxes);
return [NSKeyedArchiver archivedDataWithRootObject:[self mailboxes]] ;
}
read data from a file, when Open is selected
- (BOOL)readFromData
{
self.mailboxes = [NSKeyedUnarchiver unarchiveObjectWithData:data];
NSLog(@"mailboxes desctiption: %@ items.\n", self.mailboxes);
return YES;
}
- (id) initWithCoder: (NSCoder *)coder
{
if (self = [super init])
{
[self setProperties: [coder decodeObjectForKey
[self setEmails: [coder decodeObjectForKey
}
return self;
}
- (void) encodeWithCoder: (NSCoder *)coder
{
[coder encodeObject: properties forKey
[coder encodeObject: emails forKey
}
and similar one for emails.
Everything seems fine to me, except that I can save but cannot restore the data. I can see that mailboxes array has values when trying to read from a file.
Any idea what may be happening? Thank you all great folks for your help.
KP