如果在objective-c中声明如何写一行怎么办呢?这有适当的风格吗?
我知道用于赋值(int a = condition ? b : c)的三元运算符,但是我想调用一个方法是if(condition){ [self methodCall]; }推荐的方法来处理这一行吗?
另外还有objc风格指南吗?(想想与这个红宝石风格指南相比)在一段时间没有触及它之后回到语言让我想重新思考我如何设计我的代码.
fla*_*ian 58
三元if语句(if - else)
condition ? [self methodcall] : [self otherMethodCAll];
Run Code Online (Sandbox Code Playgroud)
单方法调用
if (condition) [self methodcall];
Run Code Online (Sandbox Code Playgroud)
mop*_*led 11
单行ruby样式if和unless语句在Objective-C中没有等价物.你可以坚持使用块,或者只是在同一行上调用方法:
if (condition) {
[self method];
}
Run Code Online (Sandbox Code Playgroud)
要么
if (condition)
[self method];
Run Code Online (Sandbox Code Playgroud)
要么
if (condition) [self method];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
28696 次 |
| 最近记录: |