Skip to content

Instantly share code, notes, and snippets.

@pcperini
Last active August 29, 2015 14:04
Show Gist options
  • Save pcperini/255ec710abbec3c5f8ce to your computer and use it in GitHub Desktop.
Save pcperini/255ec710abbec3c5f8ce to your computer and use it in GitHub Desktop.
// 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