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: mmalcolm crawford <email@hidden>
- Date: Wed, 25 May 2005 04:07:03 -0700
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:
This email sent to email@hidden