OCLint的部分规则(CoCoa 部分)

40 篇文章 0 订阅
17 篇文章 0 订阅

OCLint的部分规则(CoCoa 部分)

对OCLint的部分规则进行简单翻译解释,有部分进行了验证以及进一步分析、测试。OCLint其他相关内容如下:

--
OCLint-iOS-OC项目几种简单使用OCLint的部分规则(Basic 部分)
OCLint的部分规则(Unuseed 部分)OCLint的部分规则(Size 部分)
OCLint的部分规则(Redundant 部分)OCLint的部分规则(Naming 部分)
OCLint的部分规则(Migration 部分)OCLint的部分规则(Empty 部分)
OCLint的部分规则(Design 部分)OCLint的部分规则(Convention 部分)
OCLint的部分规则(CoCoa 部分)



1、missing hash method

      Since:0.8 定义类传送门~点击

When isEqual method is overridden, hash method must be overridden, too.

简单解释:isEqual 方法被重写, hash 方法也应该被重写.

    @implementation BaseObject
    - (BOOL)isEqual:(id)obj {
        return YES;
    }
    /*
    - (int)hash is missing; If you override isEqual you must override hash too.
    */
    @end
2、missing call to base method

      Since:0.8 定义类传送门~点击

When a method is declared with attribute((annotate(“oclint:enforce[base method]”))) annotation, all of its implementations (including its own and its sub classes) must call the method implementation in super class.

简单解释:当使用 __attribute__((annotate("oclint:enforce[must call super]"))) 注解时, 他的所有实现(包括他自己和子类)都必须调用超类的实现

    @interface UIView (OCLintStaticChecks)
    - (void)layoutSubviews __attribute__((annotate("oclint:enforce[must call super]")));
    @end
    @interface CustomView : UIView
    @end
    @implementation CustomView
    - (void)layoutSubviews {
        // [super layoutSubviews]; is enforced here
    }
    @end
3、calling prohibited method

      Since:0.10.1 定义类传送门~点击

hen a method is declared with attribute((annotate(“oclint:enforce[prohibited method]”))) annotation, all of its usages will be prohibited.

简单解释:当一个方法标记__attribute__((annotate("oclint:enforce[prohibited call]")))注解,所有的引用都将被禁止。

    @interface A : NSObject
    - (void)foo __attribute__((annotate("oclint:enforce[prohibited call]")));
    @end
    @implementation A
    - (void)foo {
    }
    - (void)bar {
        [self foo]; // calling method `foo` is prohibited.
    }
    @end
4、calling protected method

      Since:0.8 定义类传送门~点击

Even though there is no protected in Objective-C language level, in a design’s perspective, we sometimes hope to enforce a method only be used inside the class itself or by its subclass. This rule mimics the protected behavior, and alerts developers when a method is called outside its access scope.

简单解释:在Objective-C 中虽然没有protected这个概念。但是在设计的角度,我们有时希望一个方法只希望被它自己或者它的子类调用。这个方法可以模仿protected在有人调用的时候给一个警告。

    @interface A : NSObject
    - (void)foo __attribute__((annotate("oclint:enforce[protected method]")));
    @end
    @interface B : NSObject
    @property (strong, nonatomic) A* a;
    @end
     //
    @implementation B
    - (void)bar {
        [self.a foo]; // calling protected method foo from outside A and its subclasses
    }
    @end
5、missing abstract method implementation

      Since:0.8 定义类传送门~点击

Due to the Objective-C language tries to postpone the decision makings to the runtime as much as possible, an abstract method is okay to be declared but without implementations. This rule tries to verify the subclass implement the correct abstract method.

简单解释:由于Objectiveruntime特性,抽象方法可以被声明,可以不实现,该规则验证子类是否正确实现抽象方法。

    @interface Parent
    //
    - (void)anAbstractMethod __attribute__((annotate("oclint:enforce[subclass must implement]")));
    //
    @end
    @interface Child : Parent
    @end
    //
    @implementation Child
    /*
    // Child, as a subclass of Parent, must implement anAbstractMethod
    - (void)anAbstractMethod {}
    */
    @end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值