Skip to content

Instantly share code, notes, and snippets.

@InsertNetan
Last active April 30, 2016 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save InsertNetan/100e4fceda735c8dcbe73a2f578bfd34 to your computer and use it in GitHub Desktop.
Save InsertNetan/100e4fceda735c8dcbe73a2f578bfd34 to your computer and use it in GitHub Desktop.
func JSONFromFile(file: String) -> AnyObject? {
return NSBundle(forClass: self.dynamicType).pathForResource(file, ofType: "json")
.flatMap { NSData(contentsOfFile: $0) }
.flatMap(JSONObjectWithData)
}
private func JSONObjectWithData(data: NSData) -> AnyObject? {
return try? NSJSONSerialization.JSONObjectWithData(data, options: [])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment