CFString不符合协议Hashable?

Ale*_*er 1 xcode hashable swift ios8 xcode6.1

我最近更新到Xcode 6.1以便能够使用iOS 8.1,但现在我的最新项目面临一个错误.

我得到的错误是"CFString!不符合协议Hashable",对于以下行:

let attributes = [kCTForegroundColorAttributeName:UIColor.blackColor().CGColor, kCTFontAttributeName: font]
Run Code Online (Sandbox Code Playgroud)

运行Xcode 6.0.1时,我没有收到此错误.而且,Xcode 6.1非常慢.我的意思是,它实际上并没有完成加载任何东西.索引需要几分钟,而建设需要很长时间,以至于我没有设法通过......它也崩溃了.

我的主要问题是Hashable协议.那是怎么回事?

Dar*_*ren 6

这似乎是包含CF对象的词典的类型推断错误.

编译器(显然)使用第一个键/值对来推断类型的Dictionary [CFStringRef:CGColorRef],然后由于CFStringRef不符合而无法编译Hashable.

您可以通过显式声明Dictionary类型来解决此问题:

let attributes : [String:AnyObject] = [
    kCTForegroundColorAttributeName:UIColor.blackColor().CGColor, 
    kCTFontAttributeName:font
]
Run Code Online (Sandbox Code Playgroud)