Issue in "Learn the Essentials of Swift" tutorial

  1. Hello community.
  2. I have an error with "where" statement in this tutorial
  3. Xcode expects some semicolon ";" but it isn't there on official site.
  4. i have latest Xcode version.
  5. Please help, thanks in advance.
var optionalHello: String? = "Hello"
if let hello = optionalHello where hello.hasPrefix("H"), let name = optionalName {
  greeting = "\(hello), \(name)"
}

Replies

In Swift 3 we redesigned condition clauses to not use the

where
keyword; SE-0099 Restructuring Condition Clauses has the details. The upshot is that you can replace
where
in your example with a comma and it’ll work.

Clearly the Learn the Essentials of Swift tutorial should have been updated to account for this; I’d appreciate you file a bug against that, so that the folks responsible can fix this. Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thank you for explanation!


Here is bug number: 28798055