<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSSearchPathForDirectoriesInDomains(_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:@F@NSSearchPathForDirectoriesInDomains"
  },
  "title" : "NSSearchPathForDirectoriesInDomains(_:_:_:)"
}
-->

# NSSearchPathForDirectoriesInDomains(_:_:_:)

Creates a list of directory search paths.

```
func NSSearchPathForDirectoriesInDomains(_ directory: FileManager.SearchPathDirectory, _ domainMask: FileManager.SearchPathDomainMask, _ expandTilde: Bool) -> [String]
```

## Discussion

Creates a list of path strings for the specified directories in the specified domains. The list is in the order in which you should search the directories. If `expandTilde` is <doc://com.apple.documentation/documentation/Swift/true>, tildes are expanded as described in [`expandingTildeInPath`](/documentation/Foundation/NSString/expandingTildeInPath).

You should consider using the [`FileManager`](/documentation/Foundation/FileManager) methods [`urls(for:in:)`](/documentation/Foundation/FileManager/urls(for:in:)) and [`url(for:in:appropriateFor:create:)`](/documentation/Foundation/FileManager/url(for:in:appropriateFor:create:)). which return URLs, which are the preferred format.

For more information on file system utilities, see [File System Programming Guide](https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40010672).

> Note:
> The directory returned by this method may not exist. This method simply gives you the appropriate location for the requested directory. Depending on the application’s needs, it may be up to the developer to create the appropriate directory and any in between.

---

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)