<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIImage/init(contentsOfFile:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIImage(im)initWithContentsOfFile:"
  },
  "title" : "init(contentsOfFile:)"
}
-->

# init(contentsOfFile:)

Initializes and returns the image object with the contents of the specified file.

```
init?(contentsOfFile path: String)
```

## Parameters

`path`

The path to the file. This path should include the filename extension that identifies the type of the image data.

## Return Value

An initialized `UIImage` object, or `nil` if the method could not find the file or initialize the image from its contents.

## Discussion

This method loads the image data into memory and marks it as purgeable. If the data is purged and needs to be reloaded, the image object loads that data again from the specified path.

---

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)