<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/PhotogrammetrySample/init(contentsOf:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation20PhotogrammetrySampleV10contentsOfAC0B03URLV_tYaKcfc::OverloadGroup"
  },
  "title" : "init(contentsOf:)"
}
-->

# init(contentsOf:)

Asynchronously loads the image file located at URL into a `PhotogrammetrySample` with as many data fields populated as can be
found in the target file.  HEIC images captured with the `ObjectCaptureSession` will contain more advanced data fields
beyond just the image.  Which properties are populated depends on how the images were captured.
The `id` of the sample will be automatically created to be unique to the current process.
Throws:  If `url` does not point to a file URL or there is a problem  loading `url`.

```
init(contentsOf url: URL) async throws
```

## Discussion

This function is useful for making a capture image inspector or other system that needs
to operate in an asynchronous context, such as operating within the main actor.

For example:

```
func loadDepthData(contentsOf url: URL) async -> CVPixelBuffer? {
   return try? await PhotogrammetrySample(contentsOf: url).depthDataMap
}
```

---

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)