ios - 迅速 ,"Type of expression is ambiguous without more context"?

标签 ios

let fontRef = CTFontCreateWithName("ArialMT", config.fontSize, nil);
[kCTFontAttributeName : fontRef];

[kCTFontAttributeName : fontRef] 给我以下错误:

"Type of expression is ambiguous without more context"

最佳答案

您没有定义字典的类型。从您的定义来看,不清楚什么是字典类型,这是歧义原因。您需要将其分配给某些东西以确保不存在类型歧义。这也不是根本错误,因为 kCTFontAttributeNameCFString 类型,不是 Hashable,结果不能是字典,您需要先将其转换为as StringNSAttributedString 的字典类型应该是 [String: AnyObject] 所以正确的答案是 let attributes: [String: AnyObject] = [kCTFontAttributeName as String : fontRef]

ps 另外,不要将 ; 放在行尾,Swift 不再需要它,而且经常被视为不好的样式。

关于ios - 迅速 ,"Type of expression is ambiguous without more context"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37107037/

相关文章:

iphone - iOS6 和 iOS5 中 UIImage Orientation 的不同行为

iphone - 闪存 CS5.5 : Photo is rotated when capture a photo using CameraUI on iPhone

如果选中编译,iOS MPMediaQuery.artistsQuery() 不会返回每个艺术家

ios - 在 UITableView 中,cellForRowAtIndexPath 忽略前几行

ios - Vimeo 视频不适合 UIWebView,swift

ios - 为什么 UITableView 的最后一个单元格的高度用于剩余的空单元格?

ios - 如何使用不接受实时输入的 CoreML 在 Swift 中创建一个简单的相机应用程序?

ios - 如何获取我的 iOS 应用程序的本地化语言?

ios - 删除用户后 session 无效 Parse Server Swift

ios Coredata 大集插入