[swift-evolution] Guard let
Justin Oroz
justinoroz at me.com
Fri Jun 9 23:07:19 CDT 2017
First time trying to contribute, hopefully this is the proper channel to submit.
I propose an addition to the guard let statement to allow for replacement of optionals with unwrapped values.
ex)
two current options
obj.methodWithCallback() {(foo, bar) in
guard let foo = foo else {
return
}
foo.prop = “new”
}
OR
obj.methodWithCallback() {(foo, bar) in
guard foo != nil else {
return
}
foo!.prop = “new”
}
I propose the following option:
obj.methodWithCallback() {(foo, bar) in
guard foo else {
return
}
foo.prop = “new”
}
This reduces the seemingly redundant "guard let foo = foo” statement and removes the unnecessary forced optional unwrapping.
- Justin
More information about the swift-evolution
mailing list