【问题标题】:Cannot assign a value of type '[NSObject : AnyObject]' to a value of type '[String : AnyObject]!'无法将“[NSObject:AnyObject]”类型的值分配给“[String:AnyObject]!”类型的值
【发布时间】:2015-10-28 04:22:38
【问题描述】:

我从 FireBase ios-swift-chat-example 收到此错误。

【问题讨论】:

  • 试试这行let attributes = [NSForegroundColorAttributeName:cell.textView!.tintColor,NSUnderlineStyleAttributeName:1] cell.textView!.textView.linkTextAttributes = attributes
  • 所以这消除了错误消息: let attributes = [NSForegroundColorAttributeName:cell.textView!.tintColor, NSUnderlineStyleAttributeName: 1] cell.textView!.linkTextAttributes = attributes (没有额外的 textView 在单元格中。 textView!)话虽如此,您介意解释一下这里出了什么问题以及如何使用它至少通过语法检查吗?再次感谢! @EGHM
  • 我想你的意思是感谢@Dev 我只是编辑你的帖子来内嵌图片。
  • @EddiePratt,我发布了带有解释的答案。

标签: swift firebase


【解决方案1】:

在将字典分配给常量变量时​​,您不需要进行类型转换,因为您已经创建了 [String : AnyObject] 类型的字典,这是分配给 UITextView.linkTextAttributes 所需的。

let attributes = [NSForegroundColorAttributeName:cell.textView!.tintColor,NSUnderlineStyleAttributeName:1]
cell.textView!.textView.linkTextAttributes = attributes

【讨论】:

  • 对于 Swift 2 let attributes = [NSForegroundColorAttributeName:cell.textView!.tintColor,NSUnderlineStyleAttributeName:1] cell.textView!.linkTextAttributes = attributes
【解决方案2】:

检查你是在处理字符串还是字典。就我而言,我将字典作为字符串处理。

【讨论】:

    猜你喜欢
    • 2015-12-17
    • 2016-06-28
    • 1970-01-01
    • 1970-01-01
    • 2015-08-22
    • 2017-07-02
    • 2015-11-08
    • 2015-10-24
    • 1970-01-01
    相关资源
    最近更新 更多