oclint规则 Cocoa

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值