Created
April 11, 2020 09:39
-
-
Save cipolleschi/2ccae8a06de427ed751dc602af78b3d1 to your computer and use it in GitHub Desktop.
Code to load some data from the disk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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