JSON Parsing in Swift
String { get { switch self { ... case let .JSONString(s): return “\“” + s “\“” ... } } } }
And that's it![^1] This makes the operation they implemented as follows: ~~~ JavaScript for item in json["blogs"]?["blog"] { let id = blog[“id”] let name = blog[“name”] let needspassword = blog[“needspassword”] let url = blog[“url”] println(“Blog ID: \(id)”) println(“Blog Name: \(name)”) println(“Blog Needs Password: \(needspassword)”) println(“Blog URL: \(url)”) }
That's a lot easier, once a proper JSON library is implemented, anyway. Swiftz has the start of one, similar in style to what I'm proposing here.
[^1]: Or close to it anyway. I'm simplifying here. See Swiftz for a more complete JSON library.