Re: Document Loading Problem
Re: Document Loading Problem
- Subject: Re: Document Loading Problem
- From: jerome LAURENS <email@hidden>
- Date: Thu, 28 Mar 2002 10:49:57 +0100
Le jeudi 28 mars 2002, ` 02:21 AM, Michael Briscoe a icrit :
>
Hi List!
>
>
I'm working on an application that saves a document containing a view,
>
with a background pict, and a pathname to an MP3 file. I think I've got
>
the archiving process down, but when I unarchive the data is lost.
>
Here's my code:
>
>
My controller is a NSDocument <NSCoding>:
>
>
- (NSData *)dataRepresentationOfType:(NSString *)aType
>
{
>
return [NSArchiver archivedDataWithRootObject:self];
>
}
>
>
- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
>
{
>
self = [[NSUnarchiver unarchiveObjectWithData:data] retain];
>
>
return YES;
>
}
>
self is just a local variable, it is just a handle on the receiver of
the message, but the receiver will never be changed by this code.
What you should do is conform to the MVC. Your document should have a
model data object (with classical accessors) which wraps the sound and
image and implement things like this
- (NSData *)dataRepresentationOfType:(NSString *)aType
{
return [NSArchiver archivedDataWithRootObject: [self model]];
}
- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
{
[self setModel: [NSUnarchiver unarchiveObjectWith
Data:data]];
return [self model]!=nil;
}
all the coding stuff should reside in your model object only. NSDocument
is a model controller, your implementation uses it as a model...
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.