Created
September 9, 2016 16:00
-
-
Save sbishopwta/82b1726bc50992583dde04693de0515e 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