![](/img/trans.png)
[英]Swift 2.0 Type of expression is ambiguous without more context `.FlexibleHeight`
[英]Swift 2.0: Type of expression is ambiguous without more context - Dictionary
我有以下代碼在Swift 1.2中可以正常工作。 現在,我已經升級到Swift 2.0,它不再適用於以下消息:
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)
我不確定如何解決此問題,因為它過去可以正常工作。 有什么建議么?
您可以嘗試更清楚地指定字典的類型,如果這不是問題,可能會指出問題所在(如@Martin所建議的,這可能是要求解包的可選內容)。
例如:
var attributes: [String:NSObject]
= [NSFontAttributeName:self.font, NSParagraphStyleAttributeName:paragraphStyle]
@Martin R是正確的。 我通過解開self.font來修復它
var attributes:Dictionary = [NSFontAttributeName:self.font!, NSParagraphStyleAttributeName:paragraphStyle]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.