Search code examples
iosxcodeswiftswift2cgfloat

CGFloat in Swift 2.0


After updating Swift to 2.0 I need to fix my code. Automatic correction doesn't work.

func getValueForKey(key: String) -> CGFloat {
        var inch = ""
        if screenSize.height == 480 {
            // iPhone 4, 4s and below
            inch = "3.5"
        } else if screenSize.height == 568 {
            // iPhone 5, 5s
            inch = "4"
        } else if screenSize.width == 375 {
            // iPhone 6
            inch = "4.7"
        } else if screenSize.width == 414 {
            // iPhone 6+
            inch = "5.5"
        } else if screenSize.width == 768 {
            // iPad
            inch = "5.5+"
        }
        let result = values["\(key)\(inch)"]!
        //        println("\(key) - \(result)")
        return result
    }

enter image description here

I have changed it. But nothing happens and it appears again!

How to fix it?


Solution

  • To elaborate on why importing UIKit fixes this problem:

    The CGFloat struct is part of the CoreGraphics framework. UIKit by default imports Foundation which imports CoreGraphics.

    If you weren't using UIKit or were on a platform that doesn't have the UIKit framework (such as Linux), Importing the Foundation module will import CoreGraphics.