Skip to content

Instantly share code, notes, and snippets.

@frr149
Created January 19, 2017 23:43
Show Gist options
  • Save frr149/104425614894793890d6be6b1f6c89d8 to your computer and use it in GitHub Desktop.
Save frr149/104425614894793890d6be6b1f6c89d8 to your computer and use it in GitHub Desktop.
//MARK: - Loading
func loadFromLocalFile(fileName name: String, bundle: Bundle = Bundle.main) throws -> JSONArray{
if let url = bundle.URLForResource(name),
let data = try? Data(contentsOf: url),
let maybeArray = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers) as? JSONArray,
let array = maybeArray{
return array
}else{
throw StarWarsError.jsonParsingError
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment