Re: Display RTF & RTFD file in NSTextView
Re: Display RTF & RTFD file in NSTextView
- Subject: Re: Display RTF & RTFD file in NSTextView
- From: Douglas Davidson <email@hidden>
- Date: Tue, 20 Sep 2005 12:47:44 -0700
On Sep 20, 2005, at 12:08 PM, Giovanni Donelli wrote:
I am trying to display either a RTF or a RTFD file into a
NSTextView.
Does anybody have a clever way to do that?
This is one of the main purposes of NSTextView, so there are quite a
few ways to do this, starting with e.g. readRTFDFromFile:. If you're
looking for cleverness, you could take a look at the source to
TextEdit, which has some useful tricks.
On Sep 20, 2005, at 12:33 PM, Ryan Britton wrote:
Try this: (typed in mail)
NSData *data;
NSAttributedString *content;
data = [NSData dataWithContentsOfFile:@"some/path"];
if (!data)
{
return;
}
content = [[[NSAttributedString alloc] initWithRTF:data
documentAttributes:NULL] autorelease];
This is fine, but in general I would recommend that if you're going
to be reading a text document directly from a file, you let
NSAttributedString do it for you, via methods such as
initWithURL:options:documentAttributes:error: and the like. This
lets NSAttributedString perform whatever optimizations it likes with
regard to reading in the data, lets it use whatever information might
be associated with the file to help determine its type, and lets it
automatically read in packaged documents like RTFD with the same
method. The data-based methods are better left for cases where what
you naturally have is the data rather than a file, e.g. when reading
from the pasteboard.
Douglas Davidson
_______________________________________________
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