[英]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
解決此問題:
CGFloat
結構是CoreGraphics
框架的一部分。 UIKit
默認導入Foundation
,它導入CoreGraphics
。
如果您沒有使用UIKit
或在沒有UIKit
框架的平台上(例如 Linux),導入Foundation
模塊將導入CoreGraphics
。
原因是沒有庫 UIKit。
import UIKit
課前的這段代碼已經解決了這個問題。
似乎足夠使用:導入 CoreGraphics。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.