Skip to content

Instantly share code, notes, and snippets.

@cipolleschi
Last active April 18, 2020 09:51
Show Gist options
  • Select an option

  • Save cipolleschi/937074ca3a73414599300d717e9d8571 to your computer and use it in GitHub Desktop.

Select an option

Save cipolleschi/937074ca3a73414599300d717e9d8571 to your computer and use it in GitHub Desktop.
Improved code with dependencies injection.
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