Skip to content

Instantly share code, notes, and snippets.

@cipolleschi
Created April 11, 2020 09:39
Show Gist options
  • Select an option

  • Save cipolleschi/2ccae8a06de427ed751dc602af78b3d1 to your computer and use it in GitHub Desktop.

Select an option

Save cipolleschi/2ccae8a06de427ed751dc602af78b3d1 to your computer and use it in GitHub Desktop.
Code to load some data from the disk
class MyViewController: UIViewController {
var myPath: String
var content: [MyModel]
// ...
func loadContent() {
let fileManager = FileManager.default
guard
let data = fileManager.contents(atPath: myPath),
self.content = try? JSONDecoder().decode([MyModel].self, from data)
else {
self.content = []
return
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment