Forked from sbishopwta/gist:82b1726bc50992583dde04693de0515e
Created
March 23, 2018 13:41
-
-
Save vkostechko/11b6909e8e0b45d8def0ca779a2d2288 to your computer and use it in GitHub Desktop.
Swift 3 - Load JSON file
This file contains 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
let filePath = Bundle.main.pathForResource("YOUR_FILE_NAME", ofType: "json", inDirectory: nil) | |
if let filePath = filePath { | |
do { | |
let fileUrl = URL(fileURLWithPath: filePath) | |
let jsonData = try Data(contentsOf: fileUrl, options: .mappedIfSafe) | |
let json = try? JSONSerialization.jsonObject(with: jsonData) | |
} catch { | |
print(error) | |
fatalError("Unable to read contents of the file url") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
let filePath = Bundle.init(for: type(of: self)).path(forResource: "YOUR_FILE_NAME", ofType: "json")