Skip to content

Commit da0d5b3

Browse files
committed
Apply same logic to Yams NSNumber representer
1 parent 2388416 commit da0d5b3

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

Sources/SwiftGenKit/Utils/YamsSerialization.swift

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,29 @@ extension NSData: ScalarRepresentable {
5454

5555
extension NSNumber: ScalarRepresentable {
5656
public func represented() -> Node.Scalar {
57-
if let value = Bool(exactly: self) {
58-
return value.represented()
59-
} else if let value = Double(exactly: self), floor(value) != value {
60-
return value.represented()
61-
} else if let value = Int(exactly: self) {
62-
return value.represented()
57+
if CFGetTypeID(self) == CFBooleanGetTypeID() {
58+
return boolValue.represented()
6359
} else {
64-
return Double.nan.represented()
60+
switch CFNumberGetType(self) {
61+
case .sInt8Type:
62+
return int8Value.represented()
63+
case .sInt16Type:
64+
return int16Value.represented()
65+
case .sInt32Type:
66+
return int32Value.represented()
67+
case .sInt64Type:
68+
return int64Value.represented()
69+
case .charType:
70+
return uint8Value.represented()
71+
case .intType, .longType, .longLongType, .nsIntegerType:
72+
return intValue.represented()
73+
case .float32Type, .floatType:
74+
return floatValue.represented()
75+
case .float64Type, .doubleType, .cgFloatType:
76+
return doubleValue.represented()
77+
default:
78+
return Double.nan.represented()
79+
}
6580
}
6681
}
6782
}

0 commit comments

Comments
 (0)