Skip to content

Commit

Permalink
Merge pull request #168 from CodaFi/killvarsa
Browse files Browse the repository at this point in the history
Rebind variable declarations in JSON example
  • Loading branch information
CodaFi committed Jan 29, 2015
2 parents 65c9c4d + c620093 commit 78c1765
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,12 @@ final class User: JSONDecode {
}

public class func fromJSON(x : JSONValue) -> User? {
var n: String?
var a: Int?
var t: [String]?
var r: Dictionary<String, String>?
switch x {
case let .JSONObject(d):
n = d["name"] >>- JString.fromJSON
a = d["age"] >>- JInt.fromJSON
t = d["tweets"] >>- JArray<String, JString>.fromJSON
r = d["attrs"] >>- JDictionary<String, JString>.fromJSON
let n = d["name"] >>- JString.fromJSON
let a = d["age"] >>- JInt.fromJSON
let t = d["tweets"] >>- JArray<String, JString>.fromJSON
let r = d["attrs"] >>- JDictionary<String, JString>.fromJSON
// alternatively, if n && a && t... { return User(n!, a!, ...
return (User.create <^> n <*> a <*> t <*> r)
default:
Expand Down
12 changes: 4 additions & 8 deletions SwiftzTests/UserExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,12 @@ public class User: JSONDecode {
}

public class func fromJSON(x: JSONValue) -> User? {
var n: String?
var a: Int?
var t: [String]?
var r: Dictionary<String, String>?
switch x {
case let .JSONObject(d):
n = d["name"] >>- JString.fromJSON
a = d["age"] >>- JInt.fromJSON
t = d["tweets"] >>- JArray<String, JString>.fromJSON
r = d["attrs"] >>- JDictionary<String, JString>.fromJSON
let n = d["name"] >>- JString.fromJSON
let a = d["age"] >>- JInt.fromJSON
let t = d["tweets"] >>- JArray<String, JString>.fromJSON
let r = d["attrs"] >>- JDictionary<String, JString>.fromJSON
// alternatively, if n && a && t... { return User(n!, a!, ...
return (User.create <^> n <*> a <*> t <*> r)
default:
Expand Down

0 comments on commit 78c1765

Please sign in to comment.