修改EOS经验总结(1)

1:unnecessary default statement in covered switch statement

如果switch覆盖了全部就不用添加default如果不是还是需要添加default。
2:(使用对象下标)

UseObjectSubscripting¶

Since: 0.7

Name: use object subscripting

This rule locates the places that can be migrated to the new Objective-C literals with object subscripting.

This rule is defined by the following class: oclint-rules/rules/migration/ObjCObjectSubscriptingRule.cpp

Example:

void aMethod(NSArray *a, NSDictionary *d)
{
    id item = [a objectAtIndex:0];
    // id item = a[0];
  id item = [d objectForKey:@1];
    // id item = d[@1];
}

参见:https://oclint-docs.readthedocs.io/en/stable/rules/migration.html#useobjectsubscripting

为什么要这样呢?

使用的是下标方法mutableDic[key] = nil不会出错因为,而根据apple的可变字典文档的说明,传入nil会移除对应keyvalue

为什么会支持下标的使用呢?

下标的使用是iOS6以后支持的,取值和设值的原理是编译器调用了一套非正式的协议informal-protocol,这套协议的文档将下标分为两类,字典样式dictionary-style和数组样式array-style,分别要求实现对应协议的方法,从而支持下标的使用

参见:https://blog.csdn.net/xxq_2011/article/details/76147488

为了方便直接复制过来谢谢作者分享。

下标subscripting是OC开发中常用的字典和数组的取值和设值方式,其中不可变字典和数组可以取值,可变字典和数组通过继承可以取值,同时还支持设值

// 字典样式

// 字典样式
- (nullable ObjectType)objectForKeyedSubscript:(KeyType)key; // 取值
- (void)setObject:(nullable ObjectType)obj forKeyedSubscript:(KeyType )key; // 设值

*// 数组样式*

- (ObjectType)objectAtIndexedSubscript:(NSUInteger)idx ; *// 取值*

- (void)setObject:(ObjectType)obj atIndexedSubscript:(NSUInteger)idx ; *//*设置

3:If you override isEqual you must override hash too.

https://blog.csdn.net/Nathan1987_/article/details/79413299

model missing hash method

else 中代码为空

   if (calendarType == DeliveryCalendarBigType) {
     selectCalendarType = 1;
   } else {
     if (self.smallCalendatType != 0) {
          selectCalendarType = self.smallCalendatType;
     }
   }

替换成

 if (calendarType !=DeliveryCalendarBigType && **self**.smallCalendatType != 0) {
​            selectCalendarType = **self**.smallCalendatType;
​    }else{

​        selectCalendarType = 1;
​    }

4:high ncss method (行数过多)

ivar assignment outside accessors or init (变量必须初始化)

prefer early exits and continue

你可能感兴趣的:(修改EOS经验总结(1))