Created
August 29, 2015 08:25
-
-
Save mbogh/63b3bdc172ef3ce092ac to your computer and use it in GitHub Desktop.
Extension for JSONObject from https://gist.github.com/jarsen/b27de2ed9e84b84086ae
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
extension JSONObject { | |
/// Returns a JSON object initialized by reading into it the data from the file specified by a given path. | |
/// - Parameter path: The absolute path of the file from which to read data. | |
/// - Returns: A JSON object initialized by reading into it the data from the file specified by path. | |
convenience init?(contentsOfFile path: String) { | |
guard let data = NSData(contentsOfFile: path), | |
json = (try? NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments)) as? [String : AnyObject] else { return nil } | |
self.init(dictionary: json) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment