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

# arrayWithContentsOfFile:

Creates and returns an array containing the contents of the file specified by a given path.

```
+ (NSArray<id> *) arrayWithContentsOfFile:(NSString *) path;
```

## Parameters

`path`

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

## Return Value

An array containing the contents of the file specified by `aPath`. Returns `nil` if the file can’t be opened or if the contents of the file can’t be parsed into an array.

## Discussion

The array representation in the file identified by `aPath` must contain only property list objects (`NSString`, `NSData`, `NSDate`, `NSNumber`, `NSArray`, or `NSDictionary` objects). For more details, see [Property List Programming Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/PropertyLists/Introduction/Introduction.html#//apple_ref/doc/uid/10000048i). The objects contained by this array are immutable, even if the array is mutable.

## See Also

[`func write(toFile: String, atomically: Bool) -> Bool`](/documentation/Foundation/NSArray/write(toFile:atomically:))

Writes the contents of the array to a 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)