• 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
avoid initWithURL?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

avoid initWithURL?


  • Subject: avoid initWithURL?
  • From: email@hidden
  • Date: Fri, 1 Feb 2002 12:14:26 -0800

I have plain text html in a textView. I can save the text to a file and use
initWithURL to render the html in another textView. Can I somehow avoid the
temp file saving and initWithURL and render straight from the textView?

- (id)initWithHTML:(NSData *)data documentAttributes:(NSDictionary **)dict;
- (id)initWithHTML:(NSData *)data baseURL:(NSURL *)base documentAttributes:(NSDictionary **)dict;

These are both in NSAtrributedString.h in AppKit (there is a header by the same name in Foundation, don't let that throw you :->). So convert your NSString into an NSData. Then pass the NSData in to one of these methods. The version of the API where you pass in the base URL lets you have the HTML processed as if it came from a particular URL; you would use this if you were writing a browser, for instance. If you know the URL this HTML page should be considered to "live at", supply it there. A base URL tag in the HTML will be used if it is present, and I believe will override the one you may pass in (as it should).
As I recall, the dictionary is largely ignored on the way in for HTML; on the way out it will contain a variety of potentially useful keys, though.
The only tricky bit here is what encoding to use for the NSData. This works exactly as it should according to the HTML spec, I believe. Depending upon the encoding you choose, you may need to include a CHARSET tag in your HTML. See the HTML spec for more information on how encodings are handled, if you're not already on top of this.
Good luck!

Ben Haller
Stick Software


  • Prev by Date: Re: Sliding tab-pages in ProjectBuilder: custom subclass?
  • Next by Date: Re: [OT] Re: optimizing compilers
  • Previous by thread: avoid initWithURL?
  • Next by thread: Re: Need help finding examples of read/writing files in Cocoa
  • Index(es):
    • Date
    • Thread