Using FileManager and documents directory to save user created data.
FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
This file name will be used to save and retrive persisted data.
getDocumentsDirectory().appendingPathComponent(filename)
try data.write(to: url, options: .atomic)
if let data = FileManager.default.contents(atPath: url.path) {
do {
events = try PropertyListDecoder().decode([Event].self, from: data)
} catch {
throw DataPersistenceError.decodingError(error)
}
} else {
throw DataPersistenceError.noData
}