简体   繁体   English

Swift 2.0:在没有更多上下文的情况下,表达类型不明确-字典

[英]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.

相关问题 Swift 2.0类型的表达式是模糊的,没有更多的上下文`.FlexibleHeight` - Swift 2.0 Type of expression is ambiguous without more context `.FlexibleHeight` Swift 2.0:没有更多上下文的表达式类型是不明确的? - Swift 2.0: Type of Expression is ambiguous without more context? Swift 2.0:在没有更多上下文的情况下,表达类型不明确? SortInPlace - Swift 2.0: Type of Expression is ambiguous without more context? SortInPlace Swift 2.0:没有更多上下文的表达式类型不明确(使用 Parse) - Swift 2.0: Type of expression is ambiguous without more context (Using Parse) 斯威夫特2:对于字典来说,表达式类型不明确,没有更多上下文 - Swift 2: Type of expression is ambiguous without more context, for a dictionary Swift 3中的“表达类型不明确,没有更多上下文” - “Type of expression is ambiguous without more context” in Swift 3 Swift 中没有更多上下文的表达式类型不明确 - Type of expression is ambiguous without more context in Swift Swift 2:表达式在没有更多上下文的情况下是模糊的 - Swift 2: Type of expression is ambiguous without more context Swift:表达式类型不明确,没有更多上下文 - Swift: Type of expression is ambiguous without more context 在 swift 中,如果没有更多上下文,表达式类型是模棱两可的? - In swift Type of expression is ambiguous without more context?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM