Skip to content

Instantly share code, notes, and snippets.

@sbishopwta
Created September 9, 2016 16:00
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sbishopwta/82b1726bc50992583dde04693de0515e to your computer and use it in GitHub Desktop.
Save sbishopwta/82b1726bc50992583dde04693de0515e to your computer and use it in GitHub Desktop.
Swift 3 - Load JSON file
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