File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed
Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change 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+
2329protocol 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)
112116extension 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 }
You can’t perform that action at this time.
0 commit comments