Skip to content
Justice Tech School

Dates and Files

Date, DateFormatter and FileManager handle dates and files.

Example
import Foundation
let f = DateFormatter()
f.dateFormat = "yyyy-MM-dd"
print(f.string(from: Date(timeIntervalSince1970: 0)))
let url = FileManager.default.temporaryDirectory.appendingPathComponent("demo.txt")
try "hi".write(to: url, atomically: true, encoding: .utf8)
print(try String(contentsOf: url))

Exercise

Format a date.

DateFormatter().

Quiz Test

What writes a String to a file?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.