相关疑难解决方法(0)

如何在Swift中为开关盒创建一个noop块?

如何在Swift中为开关盒创建一个noop块?Swift强制您在您的情况下至少拥有一个可执行语句,包括默认语句.我试过把空{}但是Swift不会那么做.这意味着Swift的switch case在if-else之间不能完全翻译,反之亦然,因为在if-else中你可以在条件中包含空代码.

例如

switch meat {

   case "pork":
     print("pork is good")

   case "poulet":
     print("poulet is not bad")

   default:
     // I want to do nothing here
}
Run Code Online (Sandbox Code Playgroud)

swift

38
推荐指数
1
解决办法
5966
查看次数

标签 统计

swift ×1