string(forType:)
Returns a concatenation of the strings for the specified type from all the items in the receiver that contain the type.
Declaration
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:) 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.