私はほとんど、 FailingGuardsセクションがこれをカバーしていると言うでしょう:
Guard statements are required to exit in some way.
...またはNatashaのブログにあるように:
think of guard as a lightweight Assert
したがって、次のことを行う必要があります。
guard success else { return false }
ここでのguard
の利点は、コンパイラーが終了を保証することです。 例:
// This compiles fine and a bug risks going unnoticed
if !success {
// Some code here
// Forgot the return statement
}
// Compiler error, you are required to return and the bug is prevented
guard success else {
// Some code here
// Forgot the return statement
}
@RobertGummessonなので、経験則では、オプションのラップを解除する必要がない場合でも、終了が必要な障害が発生した場合は、 if
よりも$ guard
を使用します。 正しい?
@ agirault-はい、それか、単に終了する必要があります(失敗によるものかどうかは関係ありません)。
最も参考になるコメント
私はほとんど、 FailingGuardsセクションがこれをカバーしていると言うでしょう:
Guard statements are required to exit in some way.
...またはNatashaのブログにあるように:
think of guard as a lightweight Assert
したがって、次のことを行う必要があります。
ここでの
guard
の利点は、コンパイラーが終了を保証することです。 例: