Skip to content

Fixed for Swift 5.3 support #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions Sources/SwiftyJSON/SwiftyJSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -296,15 +296,26 @@ public struct JSON {
public static var null: JSON { get { return JSON(NSNull() as Any) } }
#if os(Linux)
internal static func stringFromNumber(_ number: NSNumber) -> String {
let type = CFNumberGetType(unsafeBitCast(number, to: CFNumber.self))
switch(type) {
case kCFNumberFloat32Type:
return String(number.floatValue)
case kCFNumberFloat64Type:
return String(number.doubleValue)
default:
return String(number.int64Value)
}
let type = CFNumberGetType(unsafeBitCast(number, to: CFNumber.self))
#if swift(>=5.3)
switch(type) {
case .float32Type:
return String(number.floatValue)
case .float64Type:
return String(number.doubleValue)
default:
return String(number.int64Value)
}
#else
switch(type) {
case kCFNumberFloat32Type:
return String(number.floatValue)
case kCFNumberFloat64Type:
return String(number.doubleValue)
default:
return String(number.int64Value)
}
#endif
}
#endif
}
Expand Down Expand Up @@ -1564,13 +1575,23 @@ extension NSNumber {
get {
#if os(Linux)
let type = CFNumberGetType(unsafeBitCast(self, to: CFNumber.self))
if type == kCFNumberSInt8Type &&
#if swift(>=5.3)
if type == .sInt8Type &&
(self.compare(trueNumber) == ComparisonResult.orderedSame ||
self.compare(falseNumber) == ComparisonResult.orderedSame){
return true
} else {
return false
}
#else
if type == kCFNumberSInt8Type &&
(self.compare(trueNumber) == ComparisonResult.orderedSame ||
self.compare(falseNumber) == ComparisonResult.orderedSame){
return true
} else {
return false
}
#endif
#else
let objCType = String(describing: self.objCType)
if (self.compare(trueNumber) == ComparisonResult.orderedSame && objCType == trueObjCType)
Expand Down