Created
January 19, 2017 23:43
-
-
Save frr149/104425614894793890d6be6b1f6c89d8 to your computer and use it in GitHub Desktop.
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
//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