oclint规则 Cocoa
重写isEqual必须重写Hash MustOverrideHashWithIsEqual¶
Since: 0.8
当 isEqual
方法被重写, hash
方法也应该被重写.
定义类: oclint-rules/rules/cocoa/ObjCVerifyIsEqualHashRule.cpp
Example:
@implementation BaseObject - (BOOL)isEqual:(id)obj { return YES; } /* - (int)hash is missing; If you override isEqual you must override hash too. */ @end
必须调用超类 MustCallSuper¶
Since: 0.8
当一个类使用 __attribute__((annotate("oclint:enforce[must call super]")))
注解的时候,
他的所有实现(包括他自己和子类)都必须调用超类的实现
定义类: oclint-rules/rules/cocoa/ObjCVerifyMustCallSuperRule.cpp
Example:
@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
验证禁止引用VerifyProhibitedCall¶
Since: 0.10.1
当一个方法标记 __attribute__((annotate("oclint:enforce[prohibited call]")))
注解,所有的引用都将被禁止。
定义类: oclint-rules/rules/cocoa/ObjCVerifyProhibitedCallRule.cpp
Example:
@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
验证 Protected 方法 VerifyProtectedMethod¶
Since: 0.8
protected
标记
Objective-C 虽然没有语言级别的限制, 但是从设计角度有时候希望他只能被自己以及子类访问. 此规则当开发人员调用的时候给予一个警告
定义类: oclint-rules/rules/cocoa/ObjCVerifyProtectedMethodRule.cpp
Example:
@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
子类必须实现 SubclassMustImplement¶
Since: 0.8
这条规则用来验证抽象方法是被子类实现的
定义类: oclint-rules/rules/cocoa/ObjCVerifySubclassMustImplementRule.cpp
Example:
@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
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: NSObject的isEqual方法初探
- 下一篇: 缓存技术的详解