---
title: "string(forType:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nspasteboard/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.

## Declaration

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

## Parameters

- `dataType`: The pasteboard data type to read.

## Return Value

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

Discussion This method invokes data(forType:) to obtain the string. If the string cannot be obtained, string(forType:) returns nil. See 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 or call availableType(from:) before invoking 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

### Related Documentation

- [setString(_:forType:)](appkit/nspasteboard/setstring(_:fortype:).md)

### Reading data

- [readObjects(forClasses:options:)](appkit/nspasteboard/readobjects(forclasses:options:).md)
- [NSPasteboard.ReadingOptionKey](appkit/nspasteboard/readingoptionkey.md)
- [NSPasteboard.ReadingOptions](appkit/nspasteboard/readingoptions.md)
- [pasteboardItems](appkit/nspasteboard/pasteboarditems.md)
- [index(of:)](appkit/nspasteboard/index(of:).md)
- [data(forType:)](appkit/nspasteboard/data(fortype:).md)
- [propertyList(forType:)](appkit/nspasteboard/propertylist(fortype:).md)
