Saving Data in iOS

May 31 2022 · Swift 5.5, iOS 15, Xcode 13

Part 3: Property Lists

20. Challenge: Saving Property Lists

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 19. Property Lists Anatomy Next episode: 21. Challenge: Reading Property Lists

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Notes: 20. Challenge: Saving Property Lists

This course was originally recorded in April 2020. It has been reviewed and all content and materials updated as of November 2021.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

Add a new method to your task store that also saves your data, but instead of using JSON use Property Lists. One hint that I can give you is that you have available a PList equivalent of JSONEncoder.

let tasksPListURL = URL(fileURLWithPath: "PrioritizedTasks",
                        relativeTo: FileManager.documentsDirectoryURL).appendingPathExtension("plist")
private func savePListPrioritizedTasks() {
  ...
}
do {
  let tasksData = try encoder.encode(prioritizedTasks)
  
  try tasksData.write(to: tasksPListURL, options: .atomicWrite)
} catch let error {
  print(error)
}
let encoder = PropertyListEncoder()
encoder.outputFormat = .xml
savePListPrioritizedTasks()