How senior iOS devs eliminate nested closures (arrow anti-pattern) in Swift | Live Dev Mentoring
Have you ever seen nested Swift closures shaped like an arrowhead (aka Pyramid of Doom)? 😱
Code shaped as an arrowhead is an anti-pattern caused by many nested structures such as nested conditions, switch statements, and even closures - for example:
service.method1 { result1 in
switch result1 {
case .success:
service.method2 { result2 in
switch result2 {
case .success:
service.method3 { result3 in
...
}
case .failure:
...
}
}
case failure:
service.method4 {
service.method5 {
...
}
}
}
}
So watch this mentoring session now to learn how to eliminate nested closures (with & without Swift's async/await) to make code easier to read and maintain.
Get the source code at https://github.com/nativeiosdevelopment/multiple-nested-api-call