ProtocolExtension 0.2.0

ProtocolExtension 0.2.0

carlSQ 维护。



ProtocolExtension

CI Status Version License Platform

介绍

Objective-C 类似于 Swift 的协议扩展

用法

定义协议

@protocol PETest <NSObject>

@optional

- (id)test:(id)arg1 arg2:(id)arg2 arg3:(id)arg3;

@end

定义协议默认行为

@extension(PETest)


- (id)test:(id)arg1 arg2:(id)arg2 arg3:(id)arg3 {
NSLog(@"===================>%@===%@=====%@",arg1,arg2,arg3);
[self testLog];
return [NSObject new];
}

- (void)testLog {
NSLog(@"======================class: %@",self.class);
}

@end

具体使用

@interface PEProtocolTest : NSObject<PETest>

@end

@implementation PEProtocolTest

@end

...

[[PEProtocolTest new] test:@"xxxxxxxxxxxxx" arg2:@"yyyyyyyy" arg3:@"zzzzzzzzzzzz"];

结果

===================>xxxxxxxxxxxxx===yyyyyyyy=====zzzzzzzzzzzz

======================class: PEProtocolTest

安装

pod "ProtocolExtension"

作者

陈睿

许可

ProtocolExtension 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。