在ObjC中编写条件赋值的简短方法 [英] Short way to write conditional assignment in ObjC
本文介绍了在ObjC中编写条件赋值的简短方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Objective-C编写这种代码行的方法更短吗?
Does Objective-C have an even shorter way of writing this line of code?
a = b ? b : c;
也就是说,a
等于b
,只要它不是nil
,否则不是c
.就像Ruby的运算符||=
That is, a way to say, a
is equal to b
as long it is not nil
, else c
. This is like Ruby's operator ||=
推荐答案
为您完成以下工作:
a = b ? : c;
(此语法是C的GNU扩展,因此您可能必须使用GCC而不是LLVM-
(This syntax is a GNU extension to C, so you might have to use the GCC and not LLVM - http://gcc.gnu.org/onlinedocs/gcc-3.2.3/gcc/Conditionals.html#Conditionals).
这篇关于在ObjC中编写条件赋值的简短方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文