JSONUtilities
JSONUtilities copied to clipboard
Simplify API for loading JSON from filename
Currently our API to load a JSON dictionary from a filename uses a static function:
let filename = "myjsonfile"
let dictionary = try JSONDictionary.from(filename: filename)
This could be simplified by using an initiliazer which would be a more natural and simpler way of initializing a dictionary:
extension Dictionary where Key == String, Value == Any {
init(filename: String) throws {
let dictionary: [String: Any] = /// load the dictionary from the filename
self = dictionary
}
}
let filename = "myjsonfile"
let dictionary = try JSONDictionary(filename: "something")