<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSImageRep/imageReps(withContentsOfFile:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSImageRep(cm)imageRepsWithContentsOfFile:"
  },
  "title" : "imageReps(withContentsOfFile:)"
}
-->

# imageReps(withContentsOfFile:)

Creates and returns an array of image representation objects initialized using the contents of the specified file.

```
class func imageReps(withContentsOfFile filename: String) -> [NSImageRep]?
```

## Parameters

`filename`

A full or relative pathname specifying the file to open. This string should include the filename extension.

## Return Value

An array of image representation objects. The array contains one object for each image in the specified file.

## Discussion

If sent to the `NSImageRep` class object, this method returns an array of objects (all newly allocated instances of a subclass of `NSImageRep`, chosen through the use of [`class(forFileType:)`](/documentation/AppKit/NSImageRep/class(forFileType:))) that have been initialized with the contents of the file. If sent to a subclass of `NSImageRep` that recognizes the file type, this method returns an array of objects (all instances of that subclass) that have been initialized with the contents of the file.

This method returns `nil` in any of the following cases:

- The message is sent to the `NSImageRep` class object and there are no subclasses in the `NSImageRep` class registry that handle the data in the file.
- The message is sent to a subclass of `NSImageRep` and that subclass cannot handle the data in the file.
- The `NSImageRep` subclass is unable to initialize itself with the contents of `filename`.

The `NSImageRep` subclass is initialized by creating an `NSData` object based on the contents of the file and passing it to the `imageRepsWithData:` method of the subclass. By default, the files handled include those with the extensions “`tiff`”, “`gif`”, “`jpg`”, “`pict`”, “`pdf`”, and “`eps`”.

## See Also

[`+  imageFileTypes`](/documentation/AppKit/NSImageRep/imageFileTypes())

Returns the file types supported by the image representation class or one of its subclasses.



---

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)