Re: Very Newb Question about saving with NSDocument
Re: Very Newb Question about saving with NSDocument
- Subject: Re: Very Newb Question about saving with NSDocument
- From: Ian Jackson <email@hidden>
- Date: Thu, 26 May 2005 18:48:50 +1200
Thank you very much mmalcom. Indeed it was useful to try out the
deprecated methods, but the Tiger ones are up and running just fine.
The archiving docs are certainly not unknown territory for me, but it
seemed like the more I read of the NSDocument docs, archiving docs,
my book, and some examples on the web, the more my head started
swimming. Hopefully this example will kick start my learning of the
document architecture.
Now to see if I can get printing and page setup working. The world
really needs an application that can print a single hard coded line. :o)
Ian.
On 25/05/2005, at 11:07 PM, mmalcolm crawford wrote:
On May 25, 2005, at 3:54 AM, Ian Jackson wrote:
I'm trying to learn how to do stuff with NSDocument, and already
stuck at the first hurdle - I'm trying to save something that's
not text. A BezierPath in fact. So it seems from what I've read
that if I can return something in the form of NSData, I can use
dataRepresentationofType:aType. But I don't know how to turn
something into NSData. I've already written something where I
encode the path:
If you're using Tiger you should use - (BOOL)readFromData:(NSData *)
data ofType:(NSString *)typeName error:(NSError **)outError etc. in
place of loadDataRepresentation:ofType: etc. (which is/are
deprecated).
That said, if your only instance variable is the NSBezierPath and
you just want to see how this works in the simplest case, then you
could do:
- (NSData *)dataRepresentationOfType:(NSString *)aType {
return [NSArchiver archivedDataWithRootObject:thePath];
}
- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)
aType {
NSBezierPath *path = [NSUnarchiver unarchiveObjectWithData:data];
[self setThePath:path]; // assume standard accessor methods
doing memory management
return YES;
}
For more on archiving, see <http://developer.apple.com/
documentation/Cocoa/Conceptual/Archiving/index.html>
mmalc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40xtra.co.nz
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden