简体   繁体   English

迅速地,“表达的类型是模棱两可的,没有更多的上下文”?

[英]In swift,“Type of expression is ambiguous without more context”?

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

[kCTFontAttributeName : fontRef] gives me the following error: [kCTFontAttributeName : fontRef]给我以下错误:

"Type of expression is ambiguous without more context" “表达类型不明确,没有更多上下文”

You didn't defined type of your dictionary. 您没有定义字典的类型。 From your definition it is not clear what is dictionary type, this is ambiguity reason. 从您的定义尚不清楚什么是字典类型,这是模棱两可的原因。 You need to assign it to something to ensure that there is no type ambiguity. 您需要将其分配给某些对象,以确保没有类型歧义。 Also it is not a root error, as kCTFontAttributeName is a CFString type that is not Hashable , as result can't be a key of a dictionary, you need to convert it as as String first. 这也不是根错误,因为kCTFontAttributeName是不可HashableCFString类型,因为结果不能是字典的键,您需要首先将其转换as String The type of dictionary for NSAttributedString should be [String: AnyObject] So the proper answer will be let attributes: [String: AnyObject] = [kCTFontAttributeName as String : fontRef] . NSAttributedString的字典类型应该为[String: AnyObject]因此正确的答案应该是let attributes: [String: AnyObject] = [kCTFontAttributeName as String : fontRef]

ps Also do not put ; ps也不要放; at end of lines, it is not required for Swift anymore and pretty often counted as bad style. 在行尾,Swift不再需要它,并且通常被认为是不良样式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Swift 2:表达式在没有更多上下文的情况下是模糊的 - Swift 2: Type of expression is ambiguous without more context 在Swift 3中没有更多上下文的表达式是模糊的 - Type of expression is ambiguous without more context in Swift 3 Swift 3中的“表达类型不明确,没有更多上下文” - “Type of expression is ambiguous without more context” in Swift 3 如何解决“在没有更多上下文的情况下含糊不清的表达类型”? 在迅速3.0 - how to resolve “Type of expression in ambiguous without more context”? in swift 3.0 Swift和HealthKit:在没有更多上下文的情况下,表达类型过于含糊 - Swift and HealthKit: type of expression too ambiguous without more context Swift 3:表达式类型[UIImage]在没有更多上下文的情况下是模棱两可的 - Swift 3: Expression type [UIImage] is ambiguous without more context 在 SWIFT 字符串插值中没有更多上下文的表达式类型不明确 - Type of expression is ambiguous without more context in SWIFT string interpolation Swift:“表达式类型在没有更多上下文的情况下不明确”与 URLSession - Swift: “Type of expression is ambiguous without more context” with URLSession Swift 2.0类型的表达式是模糊的,没有更多的上下文`.FlexibleHeight` - Swift 2.0 Type of expression is ambiguous without more context `.FlexibleHeight` 如果没有更多的上下文swift 4.0,表达式的类型是不明确的 - Type of expression is ambiguous without more context swift 4.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM