gpt4 book ai didi

ios - 迅速 ,"Type of expression is ambiguous without more context"?

转载 作者:行者123 更新时间:2023-11-29 01:00:10 28 4
gpt4 key购买 nike

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

[kCTFontAttributeName : fontRef] 给我以下错误:

"Type of expression is ambiguous without more context"

最佳答案

您没有定义字典的类型。从您的定义来看,不清楚什么是字典类型,这是歧义原因。您需要将其分配给某些东西以确保不存在类型歧义。这也不是根本错误,因为 kCTFontAttributeNameCFString 类型,不是 Hashable,结果不能是字典,您需要先将其转换为as StringNSAttributedString 的字典类型应该是 [String: AnyObject] 所以正确的答案是 let attributes: [String: AnyObject] = [kCTFontAttributeName as String : fontRef]

ps 另外,不要将 ; 放在行尾,Swift 不再需要它,而且经常被视为不好的样式。

关于ios - 迅速 ,"Type of expression is ambiguous without more context"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37107037/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com