判斷語句簡(jiǎn)化
判斷語句中盡量不要有復(fù)雜邏輯雹熬,用BOOL表示成立條件
for example
if (self.isIntervalStatisticOpened || (![HXMarketTools isAGuMarketId:(int)[self selectStockMarketId]] && ![HXMarketTools isHKMarket_normal:(int)[self selectStockMarketId]])) {
return;
}
簡(jiǎn)化后
BOOL isHKNormalMarket = [HXMarketTools isHKMarket_normal:(int)[self selectStockMarketId]];
BOOL isAGuMarket = [HXMarketTools isAGuMarketId:(int)[self selectStockMarketId]];
BOOL isSupportMarket = (isHKNormalMarket || isAGuMarket );
if (self.isIntervalStatisticOpened || !isSupportMarket) {
return;
}
使用代碼塊
BOOL isSupportMarket = false;
{
BOOL isHKNormalMarket = [HXMarketTools isHKMarket_normal:(int)[self selectStockMarketId]];
BOOL isAGuMarket = [HXMarketTools isAGuMarketId:(int)[self selectStockMarketId]];
isSupportMarket = (isHKNormalMarket || isAGuMarket );
}
if (self.isIntervalStatisticOpened || !isSupportMarket) {
return;
}
簡(jiǎn)化后竿报,只需要關(guān)心成立條件继谚,而不用關(guān)心具體邏輯,除非真正去修改
BOOL isSupportMarket = false;
{...}
if (self.isIntervalStatisticOpened || !isSupportMarket) {
return;
}