FileManager.SearchPathDirectory (Swift / Foundation)
Jump to navigation
Jump to search
FileManager.SearchPathDirectory (Swift / Foundation)
FileManager.SearchPathDirectory is an enum that identifies “well-known” directory locations. You typically use it with:
FileManager.default.urls(for:in:)to locate common directories. :contentReferenceoaicite:0
FileManager.default.url(for:in:appropriateFor:create:)to locate (and optionally create) a directory, and (notably) to get a temporary directory on a specific volume via.itemReplacementDirectory. :contentReferenceoaicite:1
Practical note for iOS developers: Many cases correspond to macOS “system” or user-facing folders (Desktop, Movies, PreferencePanes, etc.). In iOS app sandboxes, only a small subset is typically meaningful (most commonly
.documentDirectory,.cachesDirectory,.applicationSupportDirectory, and.libraryDirectory). Apple’s APIs still define the cases, but whether a directory is returned depends on platform, sandboxing, and domain mask.
The members (all cases)
The list below matches the canonical NSSearchPathDirectory set (the Objective-C ancestor of these directory constants), including raw values. :contentReferenceoaicite:2
Legend
- Typical path (macOS): conventional location on macOS (not guaranteed; don’t hard-code).
- iOS sandbox reality: whether it’s commonly used/meaningful in an iOS app sandbox (high-level guidance).
Directory Locations (cases)
Core app-storage cases (commonly relevant on iOS)
| Case | Raw value | What it’s for | Typical path (macOS) | iOS sandbox reality |
|---|---|---|---|---|
.documentDirectory
|
9 | User documents. :contentReferenceoaicite:3 | ~/Documents (conceptually)
|
Common; persists; user data you want backed up (unless excluded). |
.cachesDirectory
|
13 | Discardable cache files (Library/Caches). :contentReferenceoaicite:4
|
~/Library/Caches
|
Common; system may purge. |
.applicationSupportDirectory
|
14 | App support files (Library/Application Support). :contentReferenceoaicite:5
|
~/Library/Application Support
|
Common; good for non-user-facing persistent data. |
.libraryDirectory
|
5 | “Documentation, support, and configuration” (/Library). :contentReferenceoaicite:6
|
/Library (domain-dependent)
|
Often maps inside the app container (Library/...).
|
.downloadsDirectory
|
15 | The user’s downloads directory. :contentReferenceoaicite:7 | ~/Downloads
|
Usually not a meaningful concept for sandboxed iOS apps. |
User-facing media/UI folders (mostly macOS user domain)
| Case | Raw value | What it’s for | Typical path (macOS) | iOS sandbox reality |
|---|---|---|---|---|
.desktopDirectory
|
12 | The user’s Desktop. :contentReferenceoaicite:8 | ~/Desktop
|
Generally not meaningful inside an iOS app sandbox. |
.moviesDirectory
|
17 | Movies folder. :contentReferenceoaicite:9 | ~/Movies
|
Generally not meaningful inside an iOS app sandbox. |
.musicDirectory
|
18 | Music folder. :contentReferenceoaicite:10 | ~/Music
|
Generally not meaningful inside an iOS app sandbox. |
.picturesDirectory
|
19 | Pictures folder. :contentReferenceoaicite:11 | ~/Pictures
|
Generally not meaningful inside an iOS app sandbox. |
.sharedPublicDirectory
|
21 | Shared “Public” folder. :contentReferenceoaicite:12 | ~/Public
|
Generally not meaningful inside an iOS app sandbox. |
System / developer / admin locations (macOS-oriented)
| Case | Raw value | What it’s for | Typical path (macOS) | iOS sandbox reality |
|---|---|---|---|---|
.applicationDirectory
|
1 | Installed applications. :contentReferenceoaicite:13 | /Applications (domain-dependent)
|
Not typically meaningful on iOS. |
.allApplicationsDirectory
|
100 | All application directories (across domains). :contentReferenceoaicite:14 | Multiple | Not typically meaningful on iOS. |
.demoApplicationDirectory
|
2 | Unsupported apps / demo versions. :contentReferenceoaicite:15 | System-defined | Not typically meaningful on iOS. |
.adminApplicationDirectory
|
4 | System/network admin apps. :contentReferenceoaicite:16 | System-defined | Not typically meaningful on iOS. |
.developerApplicationDirectory
|
3 | Developer apps (/Developer/Applications). :contentReferenceoaicite:17
|
/Developer/Applications
|
Not typically meaningful on iOS. |
.developerDirectory
|
6 | Developer resources (/Developer). :contentReferenceoaicite:18
|
/Developer
|
Not typically meaningful on iOS. |
.documentationDirectory
|
8 | Documentation directory. :contentReferenceoaicite:19 | System-defined | Not typically meaningful on iOS. |
.coreServiceDirectory
|
10 | Core services (System/Library/CoreServices). :contentReferenceoaicite:20
|
/System/Library/CoreServices
|
Not typically meaningful on iOS. |
.userDirectory
|
7 | User home directories (/Users). :contentReferenceoaicite:21
|
/Users
|
Not meaningful in iOS sandbox. |
System configuration / integration folders (macOS-oriented)
| Case | Raw value | What it’s for | Typical path (macOS) | iOS sandbox reality |
|---|---|---|---|---|
.inputMethodsDirectory
|
16 | Input Methods (Library/Input Methods). :contentReferenceoaicite:22
|
~/Library/Input Methods
|
Not typically meaningful on iOS. |
.printerDescriptionDirectory
|
20 | Printer descriptions. :contentReferenceoaicite:23 | System-defined | Not typically meaningful on iOS. |
.preferencePanesDirectory
|
22 | System Preferences panes (Library/PreferencePanes). :contentReferenceoaicite:24
|
/Library/PreferencePanes or ~/Library/PreferencePanes
|
Not typically meaningful on iOS. |
.allLibrariesDirectory
|
101 | All library directories where resources can be stored. :contentReferenceoaicite:25 | Multiple | Not typically meaningful on iOS. |
Autosave, scripts, temporary replacement, trash
| Case | Raw value | What it’s for | Typical path (macOS) | iOS sandbox reality |
|---|---|---|---|---|
.autosavedInformationDirectory
|
11 | Autosaved docs (Library/Autosave Information). :contentReferenceoaicite:26
|
~/Library/Autosave Information
|
Not commonly used in iOS app code. |
.applicationScriptsDirectory
|
23 | Per-app user scripts folder (~/Library/Application Scripts/<code-signing-id>). :contentReferenceoaicite:27
|
~/Library/Application Scripts/<bundle-id-ish>
|
macOS sandbox feature; not an iOS concept. |
.itemReplacementDirectory
|
99 | Temporary directory used for safe file replacement workflows. :contentReferenceoaicite:28 | Volume-appropriate temp dir | Useful when doing atomic-ish replaces; platform-dependent. |
.trashDirectory
|
102 | The Trash directory. :contentReferenceoaicite:29 | ~/.Trash (non-sandboxed)
|
Exists as an API; on iOS, Apple notes it’s within the app’s sandbox for URL.trashDirectory. :contentReferenceoaicite:30
|
Usage patterns (Swift)
1) Preferred: urls(for:in:)
let fm = FileManager.default
let documents = fm.urls(for: .documentDirectory, in: .userDomainMask).first!
let caches = fm.urls(for: .cachesDirectory, in: .userDomainMask).first!
let appSup = fm.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!