Default implementation of protocol optional methods
Create protocol
@protocol Runnable <NSObject>
@injection
+ (Class)runClass;
- (BOOL)canRun;
@end
Realize the methods
@injectprotocol(Runnable)
+ (Class)runClass {
return self;
}
- (BOOL)canRun {
return YES;
}
@end
Confirm this protocol
@interface ViewController ()<Runnable>
@end
Realize injection in .m
@implementation ViewController (Injection)
injectionable
@end
Result
ProtocolInjection[10762:501490] 1 ViewController
- Add
pod 'ProtocolInjection'
to your Podfile. - Run
pod install
orpod update
. - Import <ProtocolInjection/ProtocolInjection.h>.
This library requires iOS 6.0+
and Xcode 8.0+
.
ProtocolInjection is provided under the MIT license. See LICENSE file for details.