---
title: "dataWithContentsOfMappedFile(_:)"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/nsdata/datawithcontentsofmappedfile(_:)"
---

# dataWithContentsOfMappedFile(_:)

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

## Declaration

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

## Parameters

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

## Discussion

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: 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

### Reading Data from a File

- [init(contentsOfFile:)](foundation/nsdata/init(contentsoffile:).md)
- [init(contentsOfFile:options:)](foundation/nsdata/init(contentsoffile:options:).md)
- [NSData.ReadingOptions](foundation/nsdata/readingoptions.md)
- [init(contentsOfMappedFile:)](foundation/nsdata/init(contentsofmappedfile:).md)
