Swift 2.0 中的 CGFloat
CGFloat in Swift 2.0
将 Swift 更新到 2.0 后,我需要修复我的代码。自动更正不起作用。
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
}
我改了。
但是没有任何反应,它又出现了!
如何解决?
原因是缺少库 UIKit。
import UIKit
class之前的这段代码已经解决了问题。
详细说明为什么导入 UIKit
可以解决此问题:
CGFloat
结构是 CoreGraphics
框架的一部分。 UIKit
默认导入 Foundation
而导入 CoreGraphics
.
如果您没有使用 UIKit
或在没有 UIKit
框架的平台上(例如 Linux),导入 Foundation
模块将导入 CoreGraphics
.
似乎足够使用:
导入 CoreGraphics。
将 Swift 更新到 2.0 后,我需要修复我的代码。自动更正不起作用。
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
}
我改了。 但是没有任何反应,它又出现了!
如何解决?
原因是缺少库 UIKit。
import UIKit
class之前的这段代码已经解决了问题。
详细说明为什么导入 UIKit
可以解决此问题:
CGFloat
结构是 CoreGraphics
框架的一部分。 UIKit
默认导入 Foundation
而导入 CoreGraphics
.
如果您没有使用 UIKit
或在没有 UIKit
框架的平台上(例如 Linux),导入 Foundation
模块将导入 CoreGraphics
.
似乎足够使用: 导入 CoreGraphics。