Skip to content

Instantly share code, notes, and snippets.

@eshwartm
Last active October 9, 2017 09:22
Show Gist options
  • Save eshwartm/71003ecab0289524c8ac8a4a8a3fe0f5 to your computer and use it in GitHub Desktop.
Save eshwartm/71003ecab0289524c8ac8a4a8a3fe0f5 to your computer and use it in GitHub Desktop.
func loadJson(forFilename fileName: String) -> NSDictionary? {
if let url = Bundle.main.url(forResource: fileName, withExtension: "json") {
if let data = NSData(contentsOf: url) {
do {
let dictionary = try JSONSerialization.jsonObject(with: data as Data, options: .allowFragments) as? NSDictionary
return dictionary
} catch {
print("Error!! Unable to parse \(fileName).json")
}
}
print("Error!! Unable to load \(fileName).json")
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment