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

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

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

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

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 '=' 

 

posted @ 2014-05-02 18:14  *^*  阅读(1146)  评论(0编辑  收藏  举报