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

# init(contentsOfFile:)

Initializes a newly allocated array with the contents of the file specified by a given path.

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

## Parameters

`path`

The path to a file containing a representation of an array produced by the [`write(toFile:atomically:)`](/documentation/Foundation/NSArray/write(toFile:atomically:)) method.

## Return Value

An array initialized to contain the contents of the file specified by `aPath` or `nil` if the file can’t be opened or the contents of the file can’t be parsed into an array. The returned object might be different than the original receiver.

## Discussion

The array representation in the file identified by `aPath` must contain only property list objects (`NSString`, `NSData`, `NSArray`, or `NSDictionary` objects). The objects contained by this array are immutable, even if the array is mutable.

## See Also

[`write(toFile:atomically:)`](/documentation/Foundation/NSArray/write(toFile:atomically:))

Writes the contents of the array to a file at a given path.

[`arrayWithContentsOfFile:`](/documentation/Foundation/NSArray/arrayWithContentsOfFile:)

Creates and returns an array containing the contents of the file specified by 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)