三目运算的优先级(?表达式)

时间:2014-05-06 01:13:23   收藏:0   阅读:248

今天写一个iOS的插件,高度总是出问题,检查语句感觉没有什么问题。

1
CGFloat height = [Adaptation4iOS iPhoneScreenContent].height- [SystemUtils isIos7]?20:0- _realSearchBar.frame.size.height;

 但是返回的高度总不是计算所需要的高度举个明确的例子

1
2
3
4
5
6
7
BOOL isThree = YES;
 CGFloat height = 100 - isThree?20:0- 44;
 
//it‘s return 20 , why?
 
height = 100-(isThee?20:0)-44;
//But , add parentheses,it‘s return 36 , it‘s clear , ‘?’priority is higher than ‘=‘

 

三目运算的优先级(?表达式),布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!