Skip to content

Using FileManager and documents directory to save user created data.

Notifications You must be signed in to change notification settings

alexpaul/Scheduler-Persistence

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scheduler

Using FileManager and documents directory to save user created data.

Screenshot of Main UI

scheduler app

Getting the URL to the documents directory

FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]

Appending a file name to the documents directory

This file name will be used to save and retrive persisted data.

getDocumentsDirectory().appendingPathComponent(filename)

Writing to the documents directory

try data.write(to: url, options: .atomic)

Loading data from the documents directory

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
}

About

Using FileManager and documents directory to save user created data.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages