<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URL/init(for:in:appropriateFor:create:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation3URLV3for2in14appropriateFor6createACSo21NSSearchPathDirectoryV_So0hI10DomainMaskVACSgSbtKcfc"
  },
  "title" : "init(for:in:appropriateFor:create:)"
}
-->

# init(for:in:appropriateFor:create:)

Creates a file URL for a common directory in a domain.

```
init(for directory: FileManager.SearchPathDirectory, in domain: FileManager.SearchPathDomainMask, appropriateFor url: URL? = nil, create shouldCreate: Bool = false) throws
```

## Parameters

`directory`

The search path for the commonly used directory, such as [`FileManager.SearchPathDirectory.desktopDirectory`](/documentation/Foundation/FileManager/SearchPathDirectory/desktopDirectory) or [`FileManager.SearchPathDirectory.downloadsDirectory`](/documentation/Foundation/FileManager/SearchPathDirectory/downloadsDirectory).

`domain`

The file system domain to search, which the values in [`FileManager.SearchPathDomainMask`](/documentation/Foundation/FileManager/SearchPathDomainMask) define. Specify only one domain for this parameter. You may not specify [`allDomainsMask`](/documentation/Foundation/FileManager/SearchPathDomainMask/allDomainsMask) with this initializer.

`url`

The file URL for determining the location of the returned URL. Only the volume of this parameter is relevant.

    The initializer ignores this parameter unless the directory parameter contains the value [`FileManager.SearchPathDirectory.itemReplacementDirectory`](/documentation/Foundation/FileManager/SearchPathDirectory/itemReplacementDirectory)     and the domain parameter contains the value [`userDomainMask`](/documentation/Foundation/FileManager/SearchPathDomainMask/userDomainMask)    .

`shouldCreate`

A Boolean value that indicates whether the initializer creates the directory if it doesn’t already exist.

---

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)