<!--
{
  "availability" : [
    "macCatalyst: -",
    "macOS: 10.0.0 - 10.4.0"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSDocument/dataRepresentationOfType:",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDocument(im)dataRepresentationOfType:"
  },
  "title" : "dataRepresentationOfType:"
}
-->

# dataRepresentationOfType:

A primitive method to return a data object that represents the data of the receiver in a given type.

```
- (NSData *) dataRepresentationOfType:(NSString *) type;
```

## Discussion

A primitive method overridden by subclasses to return a data object that represents the data of the receiver in a given type (`aType`). The default implementation `raises` an `NSInternalInconsistencyException`. This method is invoked by the default implementation of `fileWrapperRepresentationOfType:.`

`aType` is the type name corresponding to the value of the `CFBundleTypeName` entry in the document type’s `Info.plist` dictionary.

Here is a typical implementation:

```objc
//Document type name
NSString *MyDocumentType = @"Rich Text Format (RTF) document";
 
...
 
- (NSData *)dataRepresentationOfType:(NSString *)aType {
    NSAssert([aType isEqualToString:MyDocumentType], @"Unknown  type");
    return [textView RTFFromRange:NSMakeRange(0, [[textView textStorage]  length])];
}
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)