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

# string(forType:)

Returns a concatenation of the strings for the specified type from all the items in the receiver that contain the type.

```
func string(forType dataType: NSPasteboard.PasteboardType) -> String?
```

## Parameters

`dataType`

The pasteboard data type to read.

## Return Value

A concatenation of the strings for the specified type from all the items in the receiver that contain the type, or `nil` if none of the items contain strings of the specified type.

## Discussion

This method invokes [`data(forType:)`](/documentation/AppKit/NSPasteboard/data(forType:)) to obtain the string. If the string cannot be obtained, [`string(forType:)`](/documentation/AppKit/NSPasteboard/string(forType:)) returns `nil`. See [`data(forType:)`](/documentation/AppKit/NSPasteboard/data(forType:)) for a description of what will cause `nil` to be returned.

In macOS 10.6 and later, if the receiver contains multiple items that can provide string, RTF, or RTFD data, the text data from each item is returned as a combined result separated by newlines.

### Special Considerations

It’s a good idea to check [`types`](/documentation/AppKit/NSPasteboard/types) or call [`availableType(from:)`](/documentation/AppKit/NSPasteboard/availableType(from:)) before invoking [`string(forType:)`](/documentation/AppKit/NSPasteboard/string(forType:)). Although performing this check isn’t required, doing so can help you determine if a `nil` result from a reading method is due to something like a pasteboard timeout.

## See Also

[`setString(_:forType:)`](/documentation/AppKit/NSPasteboard/setString(_:forType:))

Sets the given string as the representation for the specified type for the first item on the receiver.



---

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)