Last active
April 18, 2020 09:51
-
-
Save cipolleschi/937074ca3a73414599300d717e9d8571 to your computer and use it in GitHub Desktop.
Improved code with dependencies injection.
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( | |
| fileManager: FileManager, | |
| path: String, | |
| jsonDecoder: JSONDecoder = JSONDecoder() | |
| ) throws { | |
| let data = fileManager.contents(atPath: path) | |
| self.content = try jsonDecoder.decode([MyModel].self, from data) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment