---
title: "rtf(from:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nstext/rtf(from:)"
---

# rtf(from:)

Returns an NSData object that contains an RTF stream corresponding to the characters and attributes within aRange, omitting any attachment characters and attributes.

## Declaration

```swift
func rtf(from range: NSRange) -> Data?
```

## Discussion

Discussion Raises an NSRangeException if any part of aRange lies beyond the end of the receiver’s characters. When writing data to the pasteboard, you can use the NSData object as the first argument to NSPasteboard’s setData(_:forType:) method, with a second argument of NSRTFPboardType.

## See Also

### Reading and writing RTF files

- [readRTFD(fromFile:)](appkit/nstext/readrtfd(fromfile:).md)
- [writeRTFD(toFile:atomically:)](appkit/nstext/writertfd(tofile:atomically:).md)
- [rtfd(from:)](appkit/nstext/rtfd(from:).md)
