当对象初始化时,您应该进行注册
- (void)viewDidLoad {
[super viewDidLoad];
@FKCOUPLING(self);
}
向注册的对象发送消息
[FKCoupling handleCoupling:@protocol(FKTestProtocol) selector:@selector(testProtocol:) args:@[@"fuck "]];
[FKCoupling handleCoupling:@protocol(FKTestProtocol) selector:@selector(testProtocolCount:) args:@[@(100)]];
找到注册对象并执行某些操作
[FKCoupling handleCoupling:@protocol(FKTestProtocol) execute:^(id<FKTestProtocol> couplingObject) {
if ([couplingObject respondsToSelector:@selector(testProtocol:)]) {
[couplingObject testProtocol:@"test"];
}
if ([couplingObject respondsToSelector:@selector(testProtocolCount:)]) {
[couplingObject testProtocolCount:8888];
}
}];
仅需协议名称、方法、参数,无需依赖
[FKCoupling handleCouplingWithProtocolName:@"FKTestProtocol" selectorName:@"testProtocolCount:" args:@[@(100)]];
[FKCoupling handleCouplingWithProtocolName:@"FKTestProtocol" selectorName:@"testProtocol:" args:@[@"fuck"]];
FKCoupling 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile
pod "FKCoupling"
carl shen
FKCoupling 根据 MIT 许可证提供。有关更多信息,请参阅 LICENSE 文件。