Skip to content

carlSQ/ProtocolExtension

Repository files navigation

ProtocolExtension

CI Status Version License Platform

Introduce

protocol extension for Objective-C like Swift

Usage

定义protocol

@protocol PETest <NSObject>

@optional

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

@end

定义protocol 默认行为

@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

Install

pod "ProtocolExtension"

Author

carl shen

License

ProtocolExtension is available under the MIT license. See the LICENSE file for more info.

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published