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

# readObjects(forClasses:options:)

Reads from the receiver objects that best match the specified array of classes.

```
func readObjects(forClasses classArray: [AnyClass], options: [NSPasteboard.ReadingOptionKey : Any]? = nil) -> [Any]?
```

## Parameters

`classArray`

An array of class objects.

    Because this method creates an instance of the first class that can read a given pasteboard item, you can order the classes in     `classArray`     to match your preferred order of representation. Classes in the array must conform to the [`NSPasteboardReading`](/documentation/AppKit/NSPasteboardReading)     protocol.

`options`

A dictionary that specifies options to refine the search for pasteboard items, for example to restrict the search to file URLs with particular content types. For valid dictionary keys, see `Pasteboard Reading Options`.

## Return Value

An array containing the best match (if any) for each of the items on the receiver that can be represented by a class specified in `classArray`. Returns `nil` if there is an error in retrieving the requested items from the pasteboard, or an empty array if no objects of the specified classes can be created.

## Discussion

Classes in `classArray` must implement the `NSPasteboardReading` protocol. Cocoa classes that implement this protocol include `NSImage`, `NSString`, `NSURL`, `NSColor`, `NSAttributedString`, and `NSPasteboardItem`.  For every item on the pasteboard, each class in the provided array will be queried for the types it can read using [`readableTypes(for:)`](/documentation/AppKit/NSPasteboardReading/readableTypes(for:)).  An instance is created of the first class found in the provided array whose readable types match a conforming type contained in that pasteboard item. Any instances that could be created from pasteboard item data is returned to the caller.  Additional options, such as restricting the search to file URLs with particular content types, can be specified with an options dictionary.

Only objects of the requested classes are returned. You can always ensure to receive one object per item on the pasteboard by including the [`NSPasteboardItem`](/documentation/AppKit/NSPasteboardItem) class in the array of classes.

Consider the following example: there are five items on the pasteboard, two contain TIFF data, two contain RTF data, one contains a private data type. The following table shows what objects you get back in the returned array for different classes in `classArray`.

|Classes in `classArray`                            |Returned objects                                                                                                            |
|---------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------|
|`NSImage`                                          |Two `NSImage` objects.                                                                                                      |
|`NSAttributedString`                               |Two `NSAttributedString` objects.                                                                                           |
|`NSImage`, `NSAttributedString`                    |Two `NSImage` objects, and two `NSAttributedString` objects.                                                                |
|`NSImage`, `NSAttributedString`, `NSPasteboardItem`|Two `NSImage` objects, two `NSAttributedString` objects, and one `NSPasteboardItem` object containing the private data type.|

## See Also

[`canReadItem(withDataConformingToTypes:)`](/documentation/AppKit/NSPasteboard/canReadItem(withDataConformingToTypes:))

Returns a Boolean value that indicates whether the receiver contains any items that conform to the specified UTIs.

[`canReadObject(forClasses:options:)`](/documentation/AppKit/NSPasteboard/canReadObject(forClasses:options:))

Returns a Boolean value that indicates whether the receiver contains any items that can be represented as an instance of any class in a given array.



---

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)