Last active
October 9, 2017 09:22
-
-
Save eshwartm/71003ecab0289524c8ac8a4a8a3fe0f5 to your computer and use it in GitHub Desktop.
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 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