comparison Simoleon/Helpers/FileHelper.swift @ 160:0c589138a6f3

Implement Conversion Box
author Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com>
date Sun, 29 Aug 2021 19:04:34 +0100
parents 84137052813d
children
comparison
equal deleted inserted replaced
159:35628bac01f5 160:0c589138a6f3
5 // Created by Dennis Concepción Martín on 26/8/21. 5 // Created by Dennis Concepción Martín on 26/8/21.
6 // 6 //
7 7
8 import Foundation 8 import Foundation
9 9
10 /* 10
11 Decode and read json file 11 func readJson<T: Decodable>(from filename: String) throws -> T {
12 */
13 func read<T: Decodable>(json filename: String) throws -> T {
14 let data: Data 12 let data: Data
15 13
16 guard let file = Bundle.main.url(forResource: filename, withExtension: nil) 14 guard let file = Bundle.main.url(forResource: filename, withExtension: nil)
17 else { 15 else {
18 throw ErrorHandling.Json.fileMissing 16 throw ErrorHandling.Json.fileMissing
30 } catch { 28 } catch {
31 throw ErrorHandling.Json.parseFailed(cause: error.localizedDescription) 29 throw ErrorHandling.Json.parseFailed(cause: error.localizedDescription)
32 } 30 }
33 } 31 }
34 32
35 /* 33 func readConfig(withKey: String) -> String? {
36 Read configuration variables from Config.xconfig
37 */
38 func readConfigVariable(withKey: String) -> String? {
39 return (Bundle.main.infoDictionary?[withKey] as? String)? 34 return (Bundle.main.infoDictionary?[withKey] as? String)?
40 .replacingOccurrences(of: "\\", with: "") 35 .replacingOccurrences(of: "\\", with: "")
41 } 36 }