comparison Simoleon/Functions/ParseJson.swift @ 47:75c1a05176f6

Refactor code
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Mon, 26 Jul 2021 20:08:20 +0100
parents e0c2bda6c51f
children
comparison
equal deleted inserted replaced
46:ce4eb7416b41 47:75c1a05176f6
6 // 6 //
7 7
8 import Foundation 8 import Foundation
9 9
10 10
11 /* 11 // Read JSON File
12 Read JSON File
13 */
14 func parseJson<T: Decodable>(_ filename: String) -> T { 12 func parseJson<T: Decodable>(_ filename: String) -> T {
15 let data: Data 13 let data: Data
16 14
17 guard let file = Bundle.main.url(forResource: filename, withExtension: nil) 15 guard let file = Bundle.main.url(forResource: filename, withExtension: nil)
18 else { 16 else {
19 fatalError("Couldn't find \(filename) in main bundle.") 17 fatalError("Couldn't find \(filename) in main bundle.")
20 } 18 }
21 19
22 do { 20 do {
23 data = try Data(contentsOf: file) 21 data = try Data(contentsOf: file)
24 } catch { 22 } catch {