swift 2.0 : Type of expression is ambiguous without more context - Dictionary

标签 swift swift2

我有以下代码在 Swift 1.2 中运行良好。现在,我已经升级到 Swift 2.0,它不再适用于以下消息:

attributes:Dictionary - Type of expression is ambiguous without more context

 var _text: NSString = self.text as NSString!
 var paragraphStyle : NSMutableParagraphStyle = NSMutableParagraphStyle()
 paragraphStyle.lineBreakMode =  lineBreakMode
 var attributes:Dictionary = [NSFontAttributeName:self.font, NSParagraphStyleAttributeName:paragraphStyle]
 var prefixTextSize: CGSize = _text.sizeWithAttributes(attributes)

我不确定如何解决这个问题,因为它过去工作正常。有什么建议吗?

最佳答案

您可以尝试更清楚地指定字典的类型,如果这不是问题,它可能会指明方向(正如@Martin 建议的那样,可能是一个需要解包的可选项)。

例如:

var attributes: [String:NSObject] 
    = [NSFontAttributeName:self.font, NSParagraphStyleAttributeName:paragraphStyle]

关于 swift 2.0 : Type of expression is ambiguous without more context - Dictionary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33066656/

相关文章:

swift - 如何让 Nil Coalescing 运算符处理闭包?

macos - CustomView 在我的项目中看起来很奇怪,但在 Playground 上很好

ios - 查找字符串的范围

ios - 我在目录中有图像。必须获取该图像并将其转换为 base64 字符串?

ios - 在 UICollectionView 中创建的 UIImageView 保持黑色

ios - 更改静态 TableView 单元格高度

Swift 给 UITableVIew 添加边距

ios - 如何在锁定屏幕上添加备注/提醒

ios - 类型 'Custom TableViewController' 不符合协议(protocol) 'UICollectionViewDataSource'

ios - adjustsFontSizeToFitWidth 或 boundingRectWithSize 何时更改 context.actualScaleFactor?