Re: Cocoa Document-based Application Template
Re: Cocoa Document-based Application Template
- Subject: Re: Cocoa Document-based Application Template
- From: Karolis Ramanauskas <email@hidden>
- Date: Thu, 26 Feb 2009 23:36:30 -0600
You have to set up how you will save your files first, this is not core
data.
You will have to, for example, create an array that will hold the objects
that you will be archiving and unarchiving to. Then you will have to modify
the dataOfType and readFromData methods:
- (id)init {
self = [super init];
if (self) {
objectsToArchive = [[NSMutableArray alloc] init];
selection = [[NSMutableArray alloc] init];
}
return self;
}
- (void)dealloc {
[objectsToArchive release];
[selection release];
[super dealloc];
}
- (void)addObject : (id)object {
if(![objectsToArchive containsObject:object]) {
[objectsToArchive addObject:object];
}
}
- (void)removeObject : (id)object {
[objectsToArchive removeObject:object];
}
- (void)setObjects : (NSMutableArray*)objects {
[objects retain];
[objectsToArchive release];
objectsToArchive = objects;
}
- (NSArray*)objects {
return objectsToArchive;
}
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError {
if ( outError != NULL ) {
*outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:
unimpErr userInfo:NULL];
}
return [NSKeyedArchiver archivedDataWithRootObject:[self objects]];
}
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName
error:(NSError **)outError {
if ( outError != NULL ) {
*outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:
unimpErr userInfo:NULL];
}
NSArray * arrayWithDataFromFile = [NSKeyedUnarchiver
unarchiveObjectWithData:data];
NSMutableArray * mutableArrayWithDataFromFile = [arrayWithDataFromFile
mutableCopy];
[self setObjects: mutableArrayWithDataFromFile];
[mutableArrayWithDataFromFile release];
return YES;
}
On Thu, Feb 26, 2009 at 11:05 PM, Richard Somers <email@hidden
> wrote:
> An application built using the standard unmodified "Cocoa Document-based
> Application" template produces an error when saving. The error message is
> "The document "Untitled" could not be saved as "newname.????".
>
> This happens on my PPC and Intel machines.
>
> Does anyone else have this problem?
>
> Mac OS X 10.5.5
> Xcode 3.1.1
>
> Richard
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden