Ios Swift 2.0中的CGFloat
在将Swift更新到2.0之后,我需要修复我的代码。自动更正不起作用Ios Swift 2.0中的CGFloat,ios,xcode,swift,swift2,cgfloat,Ios,Xcode,Swift,Swift2,Cgfloat,在将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
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
此课前代码已解决问题。要详细说明导入
UIKit
解决此问题的原因,请执行以下操作:
CGFloat
结构是CoreGraphics
框架的一部分UIKit
默认导入Foundation
,后者导入CoreGraphics
如果您没有使用UIKit
或在没有UIKit
框架的平台上(如Linux),导入Foundation
模块将导入CoreGraphics
,使用以下方法似乎就足够了:
导入CoreGraphics。hm..它对我有效…它实际上在CoreGraphics中声明,请尝试重新启动xcodeThx)导入UIKit帮助。。。我的失败(但它在…奇怪的事情发生之前起作用):D