为什么“如果让我们"似乎没有像以前在Xcode 8.3 beta中的Swift 3中那样取消装箱值? [英] Why 'if let' does not seem to unbox a value as before in Swift 3 in Xcode 8.3 beta?

查看:87
本文介绍了为什么“如果让我们"似乎没有像以前在Xcode 8.3 beta中的Swift 3中那样取消装箱值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与以前不同,我很惊讶地看到'title'现在是可选的(编译器现在生成减弱的功能:字符串插值为可选值生成调试描述;您的意思是使它显式吗?).

Unlike before, I was surprised to see that 'title' is now an optional (the compiler now generates the waning : String interpolation produces a debug description for an optional value; did you mean to make this explicit?).

为什么"if let title ="表达式不再将其取消装箱? 我应该怎么做才能在if中拆箱?

How it comes the 'if let title =' expression does no unbox it anymore? What should I do to unbox in the if?

// Go thru all publication where the tag has been found
for item in items {
  if let item = item as? [String: String?], let title = item["label"] {
    i += 1
    if let rawSummary = item["libSousTheme"] {
      print("\(i)) Tag [\(foundTag)] z[\(foundZTag)] in « \(title) »")
    }
    else {
      print("\(i)) Tag [\(foundTag)] z[\(foundZTag)] in « \(title) » (no summary!)")
    }
  }
}

推荐答案

好吧,例如,这样做可以解决问题:

Ok then doing that for example solves the issue:

如果让item =项目为? [String:String?],让title = item ["label"] ??无 { /*…*/ }

if let item = item as? [String: String?], let title = item["label"] ?? nil { /* … */ }

这篇关于为什么“如果让我们"似乎没有像以前在Xcode 8.3 beta中的Swift 3中那样取消装箱值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆