ios - 整数文字存储到 'UInt' 时溢出

标签 ios xcode swift

将 xCode 更新到 6.3 和/或 Swift 1.2 并突然出现此错误

Integer literal overflows when stored into 'UInt'* pointing a red dot below at the Hex color 0x100114151

这是我的代码:

mybuttonOutLet.setTitleColor(UIColorFromRGB(0x100114151), forState: UIControlState.Normal)

这是我的 UIColorFromRGB() 方法

func UIColorFromRGB(rgbValue: UInt) -> UIColor {
    return UIColor(
        red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
        green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
        blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
        alpha: CGFloat(1.0)
    )
}

最佳答案

0x100114151。好的,那是九个十六进制数字。假设:UInt 在您的平台上是 32 位。计算出八个十六进制数字。

换句话说,您将一个 >32 位的值分配给一个只能容纳 32 位的变量。

关于ios - 整数文字存储到 'UInt' 时溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29815459/

相关文章:

ios - Xcode 4 : How to change ${EXECUTABLE_NAME} variable's value?

ios - 表格 View 单元格选择颜色在 0 单元格之后有效但不是第一行?

ios - Swift 将数组传递给函数并返回

ios - 更新 textFieldDidBeginEditing 方法中的约束会导致文本弹回

objective-c - UITextView 未显示在生成的 PDF 上

ios - 无法在 Swift3 中检索正确保存的 NSKeyArchived 对象

swift - swift 3 中 UIView.init 和没有 init 的区别

iOS 9 : Black Background on buttons, 和某些设备上的性能错误

ios - 我如何使用搜索栏在元组中搜索?

xcode - 在 OSX 上安装 Tensorflow - clang : error: linker command failed with exit code 1