• 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: Display RTF & RTFD file in NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
  • Follow-Ups:
    • Re: Display RTF & RTFD file in NSTextView
      • From: Giovanni Donelli <email@hidden>
References: 
 >Display RTF & RTFD file in NSTextView (From: Giovanni Donelli <email@hidden>)

  • Prev by Date: NSPrintInfo bug?
  • Next by Date: Re: Transparent windows intercepting clicks
  • Previous by thread: Re: Display RTF & RTFD file in NSTextView
  • Next by thread: Re: Display RTF & RTFD file in NSTextView
  • Index(es):
    • Date
    • Thread