OC 属性

@property (nonatomic, strong) NSDictionary * _Nullable extraData;

 

swift使用 打印

Dictionary<AnyHashable, Any>
(lldb) po extraData
▿ Optional<Dictionary<AnyHashable, Any>>
  ▿ some : 2 elements
    ▿ 0 : 2 elements
      ▿ key : AnyHashable("localAddress")
        - value : "localAddress"
      - value : "江苏省无锡市锡山区厚桥街道厚安路无锡锡东科技产业园"
    ▿ 1 : 2 elements
      ▿ key : AnyHashable("virtual")
        - value : "virtual"
      - value : true

  

 

直接使用  下边代码会失败

if let dict = self.extraData as? [String:Any]{

}

 

应该使用

        if let dict = self.extraData as? Dictionary<String, Any>{
            let aVirtual = dict["virtual"] as? Bool ?? false
            let localAddress = dict["localAddress"] as? String ?? ""
        }

 

posted on 2024-07-23 13:43  懂事长qingzZ  阅读(14)  评论(0编辑  收藏  举报