Hello everyone, this is my first topic, so i am sorry if i did not post it where it should.
My suggestion would be to extend the guard support to work with try as well.
Current:
func processConfig() {
do {
let config = try loadApplicationConfig()
// Continue with config...
} catch {
// error is implicit
print("Failed to load config: \(error.localizedDescription)")
return
}
}
or
func processConfig() {
let config: ApplicationConfig
do {
config = try loadApplicationConfig()
} catch {
// error is implicit
print("Failed to load config: \(error.localizedDescription)")
return
}
// Continue with config...
}
Proposed:
func processConfig() {
guard let config = try loadApplicationConfig() else {
// error is implicit, just like it catch
print("Failed to load config: \(error.localizedDescription)")
return
}
// Continue with config...
}
I think it would work great with the cases were we dont do a lot of throwing calls and it doing a traditional do-catch simply reduces the readability through additional brackets.