0Pricing
Swift Academy · Lesson

URLs and File Paths

Locate files using URL-based APIs.

URLs and File Paths

On Apple platforms files are addressed with URL values, not bare strings. A file URL points at a location in the file system.

File URLs

Create a file URL with URL(fileURLWithPath:). It marks the URL as a local file rather than a network address.

import Foundation

let url = URL(fileURLWithPath: "/tmp/data.txt")
print(url.path)
print(url.isFileURL)

All lessons in this course

  1. URLs and File Paths
  2. Reading and Writing Data
  3. Managing Directories
  4. App Sandbox Directories
← Back to Swift Academy