代码规范

判断语句简化

判断语句中尽量不要有复杂逻辑,用BOOL表示成立条件

for example

if (self.isIntervalStatisticOpened || (![HXMarketTools isAGuMarketId:(int)[self selectStockMarketId]] && ![HXMarketTools isHKMarket_normal:(int)[self selectStockMarketId]])) {
  return;
}

简化后

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;
}

简化后,只需要关心成立条件,而不用关心具体逻辑,除非真正去修改

BOOL isSupportMarket = false;
{...}
if (self.isIntervalStatisticOpened || !isSupportMarket) {
  return;
}

你可能感兴趣的:(代码规范)