<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSPasteboard/readFileContentsType(_:toFile:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSPasteboard(im)readFileContentsType:toFile:"
  },
  "title" : "readFileContentsType(_:toFile:)"
}
-->

# readFileContentsType(_:toFile:)

Reads data representing a file’s contents from the receiver and writes it to the specified file.

```
func readFileContentsType(_ type: NSPasteboard.PasteboardType?, toFile filename: String) -> String?
```

## Parameters

`type`

The pasteboard data type to read. You should generally specify a value for this parameter. If you specify `nil`, the filename extension (in combination with the `NSCreateFileContentsPboardType` function) is used to determine the type.

`filename`

The file to receive the pasteboard data.

## Return Value

The name of the file into which the data was actually written.

## Discussion

Data of any file contents type should only be read using this method. If data matching the specified type is not found on the pasteboard, data of type `NSFileContentsPboardType` is requested.

> macOS 10.6 and later:
> In macOS 10.5 and earlier, the file contents pboard type allowed you to synthesize a pboard type for a file’s contents based on the file’s extension. In macOS 10.5 and later, using the UTI of a file to represent its contents now replaces this functionality.

### Special Considerations

You must send an [`availableType(from:)`](/documentation/AppKit/NSPasteboard/availableType(from:)) or [`types`](/documentation/AppKit/NSPasteboard/types) message before invoking [`readFileContentsType(_:toFile:)`](/documentation/AppKit/NSPasteboard/readFileContentsType(_:toFile:)).

## See Also

[`-  writeFileContents:`](/documentation/AppKit/NSPasteboard/writeFileContents(_:))

Writes the contents of the specified file to the pasteboard.



---

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)