Search code examples
swiftif-statementswift3letunboxing

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


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

Solution

  • Ok then doing that for example solves the issue:

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