Document-specific data with RTFs
Document-specific data with RTFs
- Subject: Document-specific data with RTFs
- From: David Sinclair <email@hidden>
- Date: Sat, 1 Jun 2002 21:24:41 -0700
Hi. What is the best way to store custom document-specific data with
an RTF document? I've searched the documentation and list archives,
to no avail, other than someone else who tried the same idea, but
there was no response to his question:
http://cocoa.mamasam.com/COCOADEV/2001/12/1/19871.php
Here's my code, below. I tried using
-RTFFromRange:documentAttributes: in the hopes that I could add my
own data in the documentAttributes, but when I look at the resulting
file, my data is missing. (I tried adding a simple string instead of
the array, and that didn't work either.)
So, any pointers to the *right* way to do this? This seems like a
common operation, so surely there must be a Cocoa way. Do I need to
use attachments or RTFD containers, write things into the resource
fork, or something? Any advice would be much appreciated.
- (NSData *)dataRepresentationOfType:(NSString *)aType
{
// Write text to file.
if ([aType isEqualToString:@"RTF Document"])
{
NSRange range = NSMakeRange(0, [[fTextView textStorage] length]);
NSMutableArray *array = [cast characters];
NSData *obj = [NSArchiver archivedDataWithRootObject:array];
NSMutableDictionary *dict = [NSMutableDictionary
dictionaryWithObject:obj forKey:@"Cast"];
NSData *data = [[fTextView textStorage] RTFFromRange:range
documentAttributes:dict];
[self setText
Data:data];
}
else
{
[self setText
Data:[NSData dataWithBytes:[[fTextView string] cString]
length:[[fTextView string]
cStringLength]]];
}
return [self textData];
}
--
David Sinclair - email@hidden
http://www.dejal.com/
_______________________________________________
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.