JSONUtilities icon indicating copy to clipboard operation
JSONUtilities copied to clipboard

Simplify API for loading JSON from filename

Open lucianomarisi opened this issue 7 years ago • 0 comments

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")

lucianomarisi avatar May 14 '17 11:05 lucianomarisi