Hi so here's the boilerplate code for parsing JSON files in Swift 2. Ive used this before and it works but for some reason its broken in the latest version of Xcode 7.1 and Swift 2. Any thoughts about this guys? The error is "Argument labels '(contentsOfFile:, options:, error:)' do not match any available overloads"
import Foundation
extension Dictionary {
static func loadJSONFromBundle(filename: String) -> Dictionary<String, AnyObject>? {
if let path = NSBundle.mainBundle().pathForResource(filename, ofType: "json") {
var error: NSError?
let data = NSData(contentsOfFile: path, options: NSDataReadingOptions, error: &error)
if let data = data {
let dictionary: AnyObject? = NSJSONSerialization.JSONObjectWithData(data,
options: NSJSONReadingOptions(), error: &error)
if let dictionary = dictionary as? Dictionary<String, AnyObject> {
return dictionary
} else {
print("Level file '\(filename)' is not valid JSON: \(error!)")
return nil
}
} else {
print("Could not load level file: \(filename), error: \(error!)")
return nil
}
} else {
print("Could not find level file: \(filename)")
return nil
}
}
}