Short way to write conditional assignment in ObjC

后端 未结 2 941
不思量自难忘°
不思量自难忘° 2020-12-14 07:06

Does Objective-C have an even shorter way of writing this line of code?

 a = b ? b : c;

That is, a way to say, a is equal to <

2条回答
  •  一生所求
    2020-12-14 07:44

    That's as short as you can get it in Objective-C! That's a nice little test you have there.

    The only other short way I could come up with is as follows (I wouldn't recommend it for readability reasons and it isn't as short as yours!):

    if (b) a = b; else a = c;
    

提交回复
热议问题