Last active
August 29, 2015 14:04
-
-
Save pcperini/255ec710abbec3c5f8ce to your computer and use it in GitHub Desktop.
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
// MARK: JSON Valid Types | |
protocol JSON {} | |
// MARK: - Type Aliases | |
typealias JSONDictionary = Dictionary<String, JSON> | |
typealias JSONArray = Array<JSON> | |
// MARK: - Primitives | |
extension Bool: JSON {} | |
extension Int: JSON {} | |
extension Double: JSON {} | |
extension String: JSON {} | |
// MARK: - Structures | |
extension Dictionary: JSON {} | |
extension Array: JSON {} | |
var x: Dictionary<String, JSON> = [ | |
"String": "0", | |
"Bool": true, | |
"Int": 5, | |
"Arr": ["1"], | |
"Dict": [ | |
"Arr0": ["1", "1"] | |
] | |
] | |
var z = (x["Dict"] as Dictionary<String, JSON>)._bridgeToObjectiveC() // EXC_BAD_INSTRUCTION at runtime | |
var z = (x["Dict"]! as Dictionary<String, JSON>)._bridgeToObjectiveC() // EXC_BAD_INSTRUCTION at runtime | |
var z = ((x["Dict"] as Dictionary<String, JSON>) as? NSDictionary) // NSDictionary is not a subtype of Dictionary<String, JSON> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment