Skip to content

Commit 11293b6

Browse files
committed
fix bool to int
1 parent d3e6d05 commit 11293b6

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Sources/Lookup/Lookup.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,12 @@ public extension Lookup {
548548

549549
// MARK: - Int
550550
var int: Int? {
551-
(string as NSString?)?.integerValue
551+
switch rawType {
552+
case .bool:
553+
rawBool ? 1 : 0
554+
default:
555+
(string as NSString?)?.integerValue
556+
}
552557
}
553558
var intValue: Int {
554559
int!

Tests/LookupTests/LookupTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,10 @@ struct LookupTests {
410410
}
411411
"""
412412
let clookup = Lookup(json)
413+
#expect(clookup.b.bool == true)
414+
#expect(clookup.b.int == 1)
415+
#expect(clookup.i.int == 1)
416+
#expect(clookup.i.bool == true)
413417
#expect(clookup.description.contains("true"))
414418

415419
let data = try JSONEncoder().encode(clookup)

0 commit comments

Comments
 (0)