NSScreencast Episode #129 Swift JSON
- Obj-Cの方がSwiftよりJSONパースが適当に実装できる
- parsing JSON (which provides no contracts or type guarantees) can be difficult and tedious in Swift.
- Many of the problems you are forced to deal with were easier to ignore in Objective-C
- func parseJson
- struct Episode
- func parseEpisodes(json: AnyObject) -> [Episode]
- if let array = json as? [ [ String : AnyObject ] ]
- func parseEpisode(dict: [ String : AnyObject ]) -> Episode?
- if let id = dict["id"] as? NSNumber {
- if let title = dict["title"] as? NSString {
- if let description = dict["description"] as? NSString {
- if let number = dict["episode_number"] as? NSNumber {
- if let description = dict["description"] as? NSString {
- if let title = dict["title"] as? NSString {
- if let id = dict["id"] as? NSNumber {
自分で毎回いちいち書くとしたら面倒そう