减少Swift中的括号数

有人知道有没有办法使用某种速记的速记?更具体地说,在诸如IF语句之类的东西中省略大括号
if num == 0
  // Do something

代替

if num == 0
{
  // Do something
}

当你有几个嵌套的IF,这些大括号变得相当空间消耗.

PS.我知道我可以做以下事情:

if num == 0 {
  // Do something }

但是,如果有可能的话,我仍然很好奇

你可以这样做:
let x = 10,y = 20;
let max = (x < y) ? y : x ; // So max = 20

还有这么多有趣的事情:

let max = (x < y) ? "y is greater than x" : "x is greater than y" // max = "y is greater than x"
let max = (x < y) ? true : false // max = true
let max = (x > y) ? func() : anotherFunc() // max = anotherFunc()
(x < y) ? func() : anotherFunc() // code is running func()

以下堆栈:http://codereview.stackexchange.com可以更好的为您的问题;)

编辑:注意三元运算符

By doing nothing more than replacing the ternary operator with an if else statement,the build time was reduced by 92.9%.

https://medium.com/@RobertGummesson/regarding-swift-build-time-optimizations-fc92cdd91e31#.42uncapwc

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...