[英]Swift 2.0: Type of expression is ambiguous without more context - Dictionary
I have the following code that used to work fine in Swift 1.2. 我有以下代码在Swift 1.2中可以正常工作。 Now, I've upgrade to Swift 2.0 and it no longer works with the following message: 现在,我已经升级到Swift 2.0,它不再适用于以下消息:
attributes:Dictionary - Type of expression is ambiguous without more context attribute:Dictionary-表达式类型不明确,没有更多上下文
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)
Im unsure how to fix this as it used to work fine. 我不确定如何解决此问题,因为它过去可以正常工作。 Any suggestions? 有什么建议么?
You could try specifying the type for the dictionary more clearly, if that's not the problem it might point the way (as @Martin suggests could be an optional requiring unwrapping). 您可以尝试更清楚地指定字典的类型,如果这不是问题,可能会指出问题所在(如@Martin所建议的,这可能是要求解包的可选内容)。
For example: 例如:
var attributes: [String:NSObject]
= [NSFontAttributeName:self.font, NSParagraphStyleAttributeName:paragraphStyle]
@Martin R was correct. @Martin R是正确的。 I fixed it by unwrapping self.font 我通过解开self.font来修复它
var attributes:Dictionary = [NSFontAttributeName:self.font!, NSParagraphStyleAttributeName:paragraphStyle]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.