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
- URLs and File Paths
- Reading and Writing Data
- Managing Directories
- App Sandbox Directories