Last active
February 24, 2023 16:19
-
-
Save netskink/ccc8b433cea6eac5fa4c930a447ea783 to your computer and use it in GitHub Desktop.
try catch in swift and variable visibility
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
func mySimpleFileRead(path: String) throws -> UnitsData { | |
let fileName = (path as NSString).expandingTildeInPath | |
let url = URL(fileURLWithPath: fileName) | |
let data = try Data(contentsOf: url) | |
return try JSONDecoder().decode(UnitsData.self, from: data) | |
} |
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
var unitsData2: UnitsData | |
do { | |
unitsData2 = try mySimpleFileRead(path: "~/progs/myxcode/ogrev1/ogrev1/ogrev1/units.json") | |
} catch { | |
throws JFDFileError.JSONDecodeFailed | |
} | |
print("=-+-+==.name is \(unitsData2.units[1].name)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment