Skip to content

Commit 1d7aeec

Browse files
committed
WIP
1 parent f3e4010 commit 1d7aeec

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

Sources/ReerCodable/TypeConversion.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
// THE SOFTWARE.
2222

23+
import Foundation
24+
25+
#if canImport(CoreGraphics)
26+
import CoreGraphics
27+
#endif
28+
2329
protocol TypeConvertible {
2430
static func convert(from object: Any) -> Self?
2531
}
@@ -106,16 +112,18 @@ extension FloatConvertible {
106112

107113
// MARK: - To CGFloat
108114

109-
#if canImport(CoreGraphics) && !os(Linux) && !os(Windows)
110-
import CoreGraphics
111-
115+
#if canImport(CoreGraphics) || os(Linux) || os(Windows)
112116
extension CGFloat: TypeConvertible {
113117
static func convert(from object: Any) -> CGFloat? {
114-
if let string = object as? CustomStringConvertible,
115-
let double = Double(string.description) {
118+
if let convertible = object as? CustomStringConvertible,
119+
let double = Double(convertible.description) {
116120
return CGFloat(double)
117121
} else if let bool = object as? Bool {
118-
return bool ? 1.0 : 0
122+
return CGFloat(bool ? 1 : 0)
123+
} else if let double = object as? Double {
124+
return CGFloat(double)
125+
} else if let float = object as? Float {
126+
return CGFloat(float)
119127
} else {
120128
return nil
121129
}

0 commit comments

Comments
 (0)