• 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: Very Newb Question about saving with NSDocument
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Very Newb Question about saving with NSDocument
      • From: Ian Jackson <email@hidden>
References: 
 >Very Newb Question about saving with NSDocument (From: Ian Jackson <email@hidden>)

  • Prev by Date: Re: Working set bloat in Xcode 2
  • Next by Date: Managed Objects and Unorthodox Objects
  • Previous by thread: Very Newb Question about saving with NSDocument
  • Next by thread: Re: Very Newb Question about saving with NSDocument
  • Index(es):
    • Date
    • Thread