Usage of where in if let assignment in Swift

Solution 1:

In Swift 3 this syntax has changed.

What was

if let x = y, a = b where a == x {

Is now

if let x = y, let a = b, a == x {

The justification is that each sub-clause of the if ... { is now an independent boolean test.

See the Xcode Release notes & the Swift Evolution proposal for more info about this change.

Solution 2:

Example with two conditions

if let x = y, let a = b, a == x && !x.isEmpty {

Solution 3:

In xcode 9

if let str = textField.text as String!, !str.isEmpty
{
   params[key] = str
   TextFieldHelper.setup(textField: textField)
}
else
{ 
   TextFieldHelper.error(textField: textField)
}