Skip navigation.
 
mlRe: Saving data in a document
FROM : David Dunham
DATE : Wed Jun 21 19:45:28 2006

On 21 Jun 2006, at 10:13, Chad Armstrong wrote:

> I'm working my way into learning how to work with a Document-based 
> architecture.  Below I have an example of how to save the data from 
> a text view.  This works great in just saving that data, but how do 
> I go about saving other data?  What if I want to be able to save 
> other information, such as version information, or the date that 
> this document was last read/modified, etc?  Also, how would I then 
> extract the data from the saved file?  Would this involve a 
> dictionary format, similar to saving user preferences?
>
> - (NSData *)dataRepresentationOfType:(NSString *)aType
> {
>    // Insert code here to write your document from the given 
> data.  You can also choose to override -
> fileWrapperRepresentationOfType: or -writeToFile:ofType: instead.
>    // return nil;
>     
>     NSRange range = NSMakeRange(0, [[commentsTextView textStorage] 
> length]);
>     return [commentsTextView RTFDFromRange:range];
> }


Just save the text in the data fork and the other stuff in the 
resource... oh yeah, they don't like that any more.

Yeah, you will need to come up with your own format. Or archive 
objects using NSKeyedArchiver, and save the resulting data:

NSMutableData* d = [NSMutableData data];
NSKeyedArchiver* a = [[NSKeyedArchiver alloc] 
initForWritingWithMutableData: d];
[a encodeInt: kDocumentVersion forKey: key_DocumentVersion];
[a encodeObject: rtf forKey: key_rtfData];

------------
David Dunham  <email_removed>  http://www.pensee.com/dunham/
"No matter how far you have gone on a wrong road, turn back." - 
Turkish proverb

Related mailsAuthorDate
mlSaving data in a document Chad Armstrong Jun 21, 19:13
mlRe: Saving data in a document David Dunham Jun 21, 19:45