Why 'if let' does not seem to unbox a value as before in Swift 3 in Xcode 8.3 beta?

人盡茶涼 提交于 2019-12-12 05:59:08

问题


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?).

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!)")
    }
  }
}

回答1:


Ok then doing that for example solves the issue:

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



来源:https://stackoverflow.com/questions/42543512/why-if-let-does-not-seem-to-unbox-a-value-as-before-in-swift-3-in-xcode-8-3-be

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!