Skip to content

Commit b19da15

Browse files
committed
Change NSNumber to initialize with CFNumberCreate()
1 parent 358b4f3 commit b19da15

File tree

3 files changed

+170
-112
lines changed

3 files changed

+170
-112
lines changed

Foundation/JSONEncoder.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
import CoreFoundation
14+
1315
//===----------------------------------------------------------------------===//
1416
// JSON Encoder
1517
//===----------------------------------------------------------------------===//
@@ -1742,7 +1744,7 @@ extension _JSONDecoder {
17421744
}
17431745

17441746
// TODO: Add a flag to coerce non-boolean numbers into Bools?
1745-
guard number._objCType == .Bool else {
1747+
guard number._cfTypeID == CFBooleanGetTypeID() else {
17461748
throw DecodingError._typeMismatch(at: self.codingPath, expectation: type, reality: value)
17471749
}
17481750

Foundation/NSCFBoolean.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ internal class __NSCFBoolean : NSNumber {
7878
override var objCType: UnsafePointer<Int8> {
7979
// This must never be fixed to be "B", although that would
8080
// cause correct old-style archiving when this is unarchived.
81-
return UnsafePointer<Int8>(bitPattern: UInt(_NSSimpleObjCType.Char.rawValue.value))!
81+
func _objCType(_ staticString: StaticString) -> UnsafePointer<Int8> {
82+
return UnsafeRawPointer(staticString.utf8Start).assumingMemoryBound(to: Int8.self)
83+
}
84+
return _objCType("c")
8285
}
8386

8487
internal override func _cfNumberType() -> CFNumberType {

0 commit comments

Comments
 (0)