Retired Document
Important: This document may not represent best practices for current development. Links to downloads and other resources may no longer be valid.
Reading and Writing RTFD Data
The NSRTFDPboardType is used for the contents of an RTFD file package (a directory containing an RTF text file and one or many image files). There are several ways to work with RTFD data. If you have an NSFileWrapper object that represents an RTFD file wrapper, you can send it a serializedRepresentation message to return the RTFD data and write that to the pasteboard as follows:
NSFileWrapper *tempRTFDData = [[[NSFileWrapper alloc] |
initWithPath:@"/tmp/MyTemporaryRTFDDocument.rtfd"] autorelease]; |
[pboard setData:[tempRTFDData serializedRepresentation] |
forType:NSRTFDPboardType]; |
In addition to NSFileWrapper, instances of classes such as NSAttributedString and NSText can return RTFD data. If you are using one of these classes, you can write an RTFD representation of their contents to the pasteboard as follows:
NSAttributedString *attrString = /* get an attributed string */; |
NSRange wholeStringRange = NSMakeRange(0, [attrString length]); |
NSData *rtfdData = [attrString RTFDFromRange:wholeStringRange |
documentAttributes:nil]; |
[pboard setData:rtfdData forType:NSRTFDPboardType]; |
Note that the NSText method does not require the documentAttributes parameter.
Copyright © 2009 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2009-01-20