NSObject+ProtocolChecker.h
1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
// NSObject+ProtocolChecker.h
// BBAPods
//
// Created by Yunpeng Li on 2017/11/8.
// Copyright © 2017年 Baidu. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "BDPFoundationDefines.h"
/**
* 这个扩展用于【严格】校验对象是否实现某个协议(仅DEBUG模式下有效)
*
* BBAAssertImplementProtocol(obj, protocol)既会校验协议中的实例方法,也会校验类方法
* BBAAssertClassImplementProtocol(class, protocol)只校验协议中的类方法
*/
#ifdef DEBUG
#define BBAAssertImplementProtocol(OBJ, PROTOCOL) [(NSObject *)OBJ bba_assertProtocol: @protocol(PROTOCOL)]
#define BBAAssertClassImplementProtocol(CLASS, PROTOCOL) [CLASS bba_assertProtocol: @protocol(PROTOCOL) onlyClassMethod:NO]
#else
#define BBAAssertImplementProtocol(obj, PROTOCOL)
#define BBAAssertClassImplementProtocol(clazz, Protocol)
#endif
@interface NSObject (ProtocolChecker)
/// 既会校验协议中的实例方法,也会校验类方法(推荐直接使用宏定义BBAAssertImplementProtocol)
- (void)bba_assertProtocol:(Protocol *)protocol BDP_FOUNDATION_DEPRECATED("please use bdp_assertProtocol:");
- (void)bdp_assertProtocol:(Protocol *)protocol;
/// 校验协议(推荐直接使用宏定义BBAAssertClassImplementProtocol)
+ (void)bba_assertProtocol:(Protocol *)protocol onlyClassMethod:(BOOL)isOnly BDP_FOUNDATION_DEPRECATED("please use bdp_assertProtocol:onlyClassMethod:");
+ (void)bdp_assertProtocol:(Protocol *)protocol onlyClassMethod:(BOOL)isOnly;
@end