Merging collapsible if
statements increases the code’s readability.
Noncompliant Code Example
if condition1 {
if condition2 {
doSomething()
}
}
if let y = someOptional {
if x > 0 {
doSomething()
}
}
Compliant Solution
if condition1 && condition2 {
doSomething()
}
if let y = someOptional where x > 0 {
doSomething()
}
if x > 0, let y = someOptional {
doSomething()
}