Skip to content

Commit

Permalink
Merge pull request #887 from SwiftyJSON/bool-value
Browse files Browse the repository at this point in the history
Add "yes" and "1" to string.boolValue array
  • Loading branch information
wongzigii committed Sep 8, 2017
2 parents 6835ea4 + 50ecfbe commit 29957c7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 1 addition & 3 deletions Source/SwiftyJSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -855,9 +855,7 @@ extension JSON { // : Swift.Bool
case .number:
return self.rawNumber.boolValue
case .string:
return ["true", "y", "t"].contains { (truthyString) in
return self.rawString.caseInsensitiveCompare(truthyString) == .orderedSame
}
return ["true", "y", "t", "yes", "1"].contains { self.rawString.caseInsensitiveCompare($0) == .orderedSame }
default:
return false
}
Expand Down
4 changes: 3 additions & 1 deletion Tests/SwiftyJSONTests/SubscriptTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ class SubscriptTests: XCTestCase {
}

func testDictionaryAllBool() {
var json: JSON = ["t": true, "f": false, "false": false, "tr": true, "true": true]
var json: JSON = ["t": true, "f": false, "false": false, "tr": true, "true": true, "yes": true, "1": true]
XCTAssertTrue(json["1"] == true)
XCTAssertTrue(json["yes"] == true)
XCTAssertTrue(json["t"] == true)
XCTAssertTrue(json["f"] == false)
XCTAssertTrue(json["false"] == false)
Expand Down

0 comments on commit 29957c7

Please sign in to comment.