10
我只是迁移到Xcode7/IOS9并且我的代码的某些部分不兼容。IOS9 - 无法用类型为'(String)'的参数列表调用'count'
我碰到下面的错误在Xcode:
“不能援引 '计数' 有型 '(串)' 参数列表”
这是我的代码:
let index = rgba.startIndex.advancedBy(1)
let hex = rgba.substringFromIndex(index)
let scanner = NSScanner(string: hex)
var hexValue: CUnsignedLongLong = 0
if scanner.scanHexLongLong(&hexValue)
{
if count(hex) == 6
{
red = CGFloat((hexValue & 0xFF0000) >> 16)/255.0
green = CGFloat((hexValue & 0x00FF00) >> 8)/255.0
blue = CGFloat(hexValue & 0x0000FF)/255.0
}
else if count(hex) == 8
{
red = CGFloat((hexValue & 0xFF000000) >> 24)/255.0
green = CGFloat((hexValue & 0x00FF0000) >> 16)/255.0
blue = CGFloat((hexValue & 0x0000FF00) >> 8)/255.0
alpha = CGFloat(hexValue & 0x000000FF) /255.0
}
可能重复[在Swift 1.2和Swift 2.0中的字符串长度](http://stackoverflow.com/questions/29575140/string-length-in-swift-1-2-and-swift-2-0) – Moritz
在Swift 2中:'十六进制。 characters.count' – Moritz
谢谢,您的解决方案工作,在您发布答案的那一刻,我在API的github上也找到了答案。 :) – f1rstsurf