J A S K I E R
J A S K I E R

Reputation: 2184

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?

Upvotes: 1

Views: 427

Answers (3)

ingconti
ingconti

Reputation: 11636

seems enough using: import CoreGraphics.

Upvotes: 0

JAL
JAL

Reputation: 42449

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.

Upvotes: 1

J A S K I E R
J A S K I E R

Reputation: 2184

The reason was absence of library UIKit.

import UIKit

This code before class has solved the problem.

Upvotes: 0

Related Questions