【问题标题】:CGFloat in Swift 2.0Swift 2.0 中的 CGFloat
【发布时间】:2016-04-21 19:57:28
【问题描述】:

将 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
    }

我已经改了。 但是什么也没发生,它又出现了!

如何解决?

【问题讨论】:

  • hm..它对我有用..它实际上在 CoreGraphics 中声明,尝试重新启动你的 xcode
  • Thx) import UIKit 帮助......我失败了(但它之前工作过......奇怪的事情发生了:D

标签: ios xcode swift swift2 cgfloat


【解决方案1】:

详细说明为什么导入UIKit 可以解决此问题:

CGFloat 结构是CoreGraphics 框架的一部分。 UIKit 默认导入 Foundation,后者导入 CoreGraphics

如果您没有使用UIKit 或在没有UIKit 框架的平台(例如Linux)上,导入Foundation 模块将导入CoreGraphics

【讨论】:

    【解决方案2】:

    原因是没有库 UIKit。

    import UIKit
    

    课前的这段代码解决了这个问题。

    【讨论】:

      【解决方案3】:

      似乎足够使用: 导入 CoreGraphics。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-10
        • 1970-01-01
        • 2016-03-21
        • 2018-10-12
        • 2017-04-26
        • 2014-07-31
        相关资源
        最近更新 更多