Skip to content
This repository was archived by the owner on Oct 19, 2024. It is now read-only.

Commit a494d78

Browse files
committed
Revert "Fix wrong ObjC type mapping (#65)"
This reverts commit 1c7bb78, due to #67.
1 parent 22f302d commit a494d78

File tree

3 files changed

+13
-43
lines changed

3 files changed

+13
-43
lines changed

Sources/AnyCodable/AnyEncodable.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,21 @@ extension _AnyEncodable {
109109
#if canImport(Foundation)
110110
private func encode(nsnumber: NSNumber, into container: inout SingleValueEncodingContainer) throws {
111111
switch Character(Unicode.Scalar(UInt8(nsnumber.objCType.pointee))) {
112-
case "B":
112+
case "c", "C":
113113
try container.encode(nsnumber.boolValue)
114-
case "c":
115-
try container.encode(nsnumber.int8Value)
116114
case "s":
115+
try container.encode(nsnumber.int8Value)
116+
case "i":
117117
try container.encode(nsnumber.int16Value)
118-
case "i", "l":
118+
case "l":
119119
try container.encode(nsnumber.int32Value)
120120
case "q":
121121
try container.encode(nsnumber.int64Value)
122-
case "C":
123-
try container.encode(nsnumber.uint8Value)
124122
case "S":
123+
try container.encode(nsnumber.uint8Value)
124+
case "I":
125125
try container.encode(nsnumber.uint16Value)
126-
case "I", "L":
126+
case "L":
127127
try container.encode(nsnumber.uint32Value)
128128
case "Q":
129129
try container.encode(nsnumber.uint64Value)

Tests/AnyCodableTests/AnyCodableTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class AnyCodableTests: XCTestCase {
7474

7575
let expected = """
7676
{
77-
"boolean": 1,
77+
"boolean": true,
7878
"integer": 42,
7979
"double": 3.141592653589793,
8080
"string": "string",

Tests/AnyCodableTests/AnyEncodableTests.swift

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class AnyEncodableTests: XCTestCase {
4343

4444
let expected = """
4545
{
46-
"boolean": 1,
46+
"boolean": true,
4747
"integer": 42,
4848
"double": 3.141592653589793,
4949
"string": "string",
@@ -70,16 +70,7 @@ class AnyEncodableTests: XCTestCase {
7070
func testEncodeNSNumber() throws {
7171
let dictionary: [String: NSNumber] = [
7272
"boolean": true,
73-
"char": -127,
74-
"int": -32767,
75-
"short": -32767,
76-
"long": -2147483647,
77-
"longlong": -9223372036854775807,
78-
"uchar": 255,
79-
"uint": 65535,
80-
"ushort": 65535,
81-
"ulong": 4294967295,
82-
"ulonglong": 18446744073709615,
73+
"integer": 42,
8374
"double": 3.141592653589793,
8475
]
8576

@@ -90,37 +81,16 @@ class AnyEncodableTests: XCTestCase {
9081

9182
let expected = """
9283
{
93-
"boolean": 1,
94-
"char": -127,
95-
"int": -32767,
96-
"short": -32767,
97-
"long": -2147483647,
98-
"longlong": -9223372036854775807,
99-
"uchar": 255,
100-
"uint": 65535,
101-
"ushort": 65535,
102-
"ulong": 4294967295,
103-
"ulonglong": 18446744073709615,
84+
"boolean": true,
85+
"integer": 42,
10486
"double": 3.141592653589793,
10587
}
10688
""".data(using: .utf8)!
10789
let expectedJSONObject = try JSONSerialization.jsonObject(with: expected, options: []) as! NSDictionary
10890

10991
XCTAssertEqual(encodedJSONObject, expectedJSONObject)
11092
XCTAssert(encodedJSONObject["boolean"] is Bool)
111-
112-
XCTAssert(encodedJSONObject["char"] is Int8)
113-
XCTAssert(encodedJSONObject["int"] is Int16)
114-
XCTAssert(encodedJSONObject["short"] is Int32)
115-
XCTAssert(encodedJSONObject["long"] is Int32)
116-
XCTAssert(encodedJSONObject["longlong"] is Int64)
117-
118-
XCTAssert(encodedJSONObject["uchar"] is UInt8)
119-
XCTAssert(encodedJSONObject["uint"] is UInt16)
120-
XCTAssert(encodedJSONObject["ushort"] is UInt32)
121-
XCTAssert(encodedJSONObject["ulong"] is UInt32)
122-
XCTAssert(encodedJSONObject["ulonglong"] is UInt64)
123-
93+
XCTAssert(encodedJSONObject["integer"] is Int)
12494
XCTAssert(encodedJSONObject["double"] is Double)
12595
}
12696

0 commit comments

Comments
 (0)