• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Document Loading Problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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 unarchiveObjectWithData: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.

References: 
 >Document Loading Problem (From: Michael Briscoe <email@hidden>)

  • Prev by Date: NSCell problems again!
  • Next by Date: Re: Verification of a bug
  • Previous by thread: Document Loading Problem
  • Next by thread: Re: Document Loading Problem
  • Index(es):
    • Date
    • Thread