我有以下警卫片,它产生的错误是"护卫体可能无法通过".怎么了?
guard NSFileManager.defaultManager().fileExistsAtPath(appBundlePath) else {
print("App bundle doesnt exist")
}
Run Code Online (Sandbox Code Playgroud)
这是上面答案中解释的示例,以使其更清楚。
在更外部的程序范围内保护语句。
guard false else {
print("Condition is not true ")
}
print("Condition met")
Run Code Online (Sandbox Code Playgroud)
此代码 s 产生此错误语句
错误:如果guard statement.playground:1:1: error: 'guard' body may not fall through,考虑使用'return'或'throw'退出作用域
简单的错误消息意味着,您需要使用 return、break、continue 或 throw 语句从保护语句转移程序控制权。
带返回传输控制语句
guard false else {
print("Condition is not true")
return
}
print("Condition met")
Run Code Online (Sandbox Code Playgroud)
控制台输出
满足条件
| 归档时间: |
|
| 查看次数: |
9244 次 |
| 最近记录: |