Why 'if let' does not seem to unbox a valu

2019-09-19 08:26发布

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条回答
老娘就宠你
2楼-- · 2019-09-19 09:00

Ok then doing that for example solves the issue:

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

查看更多
登录 后发表回答