Swift 2:表达式的类型是不明确的,没有更多的上下文NSDictionary



编译错误:表达式类型不明确,没有更多上下文

let navBarAttributesDictionary: [NSObject: AnyObject]? = [
        NSForegroundColorAttributeName: UIColor.whiteColor(),
        NSFontAttributeName: UIFont(name: "", size: 15)
    ]

我不能真正重现你的问题,因为你的代码首先不编译其他原因-修复这些只是修复一切:p

let navBarAttributesDictionary: [NSObject: AnyObject]? = [
    NSForegroundColorAttributeName: UIColor.whiteColor(),
    NSFontAttributeName: UIFont(name: "Helvetica", size: 15)!
]

到目前为止,只有发布的代码片段的问题。

注意正如@LeoDabus所提到的:如果你想将字典作为textAttributes分配给一些有属性的文本,你必须将其类型更改为[String: AnyObject]?

let navBarAttributesDictionary: [String: AnyObject]? = [
    NSForegroundColorAttributeName: UIColor.whiteColor(),
    NSFontAttributeName: UIFont(name: "Helvetica", size: 15)!
]

最新更新