<!--
{
  "availability" : [
    "iOS: 2.0.0 - 8.0.0",
    "iPadOS: 2.0.0 - 8.0.0",
    "macCatalyst: 13.1.0 - 13.1.0",
    "macOS: 10.0.0 - 10.10.0",
    "tvOS: 9.0.0 - 9.0.0",
    "visionOS: 1.0.0 - 1.0.0",
    "watchOS: 2.0.0 - 2.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSData/dataWithContentsOfMappedFile(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSData(cm)dataWithContentsOfMappedFile:"
  },
  "title" : "dataWithContentsOfMappedFile(_:)"
}
-->

# dataWithContentsOfMappedFile(_:)

Creates a data object from the mapped file at a given path.

```
class func dataWithContentsOfMappedFile(_ path: String) -> Any?
```

## Parameters

`path`

The absolute path of the file from which to read data.

## Discussion

This method returns `nil` if the data object could not be created

Because of file mapping restrictions, this method should only be used if the file is guaranteed to exist for the duration of the data object’s existence. It is generally safer to use the [`dataWithContentsOfFile:`](/documentation/Foundation/NSData/dataWithContentsOfFile:) method.

This methods assumes mapped files are available from the underlying operating system. A mapped file uses virtual memory techniques to avoid copying pages of the file into memory until they are actually needed.

## See Also

[`+  dataWithContentsOfFile:`](/documentation/Foundation/NSData/dataWithContentsOfFile:)

Creates a data object by reading every byte from the file at a given 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)