Reference

FileManager (iOS)

FileManager is the Foundation class iOS apps use to read, create, move, copy, and delete files and directories inside their sandbox. It exposes URLs for system locations (Documents, Caches, tmp) and reports per-file size and dates, so a storage cleaner relies on it to enumerate and remove reclaimable files.

iOS developmentiOSiPadOS

FileManager (iOS)

Also known as: filemanager swift, nsfilemanager

FileManager is the Foundation class iOS apps use to read, create, move, copy, and delete files and directories inside their sandbox. It exposes URLs for system locations (Documents, Caches, tmp) and reports per-file size and dates, so a storage cleaner relies on it to enumerate and remove reclaimable files.

  • FileManager.default is the shared instance most apps use for file operations.
  • All paths must resolve inside the app sandbox; apps cannot freely browse other apps' files.
  • Per-file size and dates come from URL resource values like .fileSizeKey and .contentModificationDateKey.

What FileManager does

FileManager is Foundation's high-level interface to the file system, available in Swift and Objective-C (where it was historically called NSFileManager). Most apps use the shared instance, FileManager.default, for routine operations.

It performs the core operations a cleaner needs: contentsOfDirectory(at:includingPropertiesForKeys:) to list a folder, removeItem(at:) to delete a file or directory tree, and moveItem/copyItem to relocate data. Because iOS apps are sandboxed, every path FileManager touches must resolve inside the app's own container.

Finding and measuring files

FileManager locates standard directories with urls(for:in:) and url(for:in:appropriateFor:create:), passing constants like .documentDirectory, .cachesDirectory, or .applicationSupportDirectory scoped to .userDomainMask. The temporary folder is read from FileManager.default.temporaryDirectory.

To size files, a cleaner fetches resource values such as .fileSizeKey, .totalFileAllocatedSizeKey, and .contentModificationDateKey via URL.resourceValues(forKeys:) or by passing those keys to a directoryEnumerator(at:includingPropertiesForKeys:options:). The enumerator walks a tree lazily, which keeps memory low when scanning large folders.

Related terms

Keep reading the reference.

Act on it

Guides and tools for this topic.