我是目标 C 的新手,并试图实现反对(依赖注入器)。
但它在下面不起作用的是我正在使用的代码
My Protocol File
#import <Foundation/Foundation.h>
@protocol InfoquestProtocolTest <NSObject>
-(void):nothing;
@end
My .h file is below
#import <Foundation/Foundation.h>
# import "InfoquestProtocolTest.h"
@interface InfoquestImplementation : NSObject<InfoquestProtocolTest>
@end
my .m file implementing protocol
#import "InfoquestImplementation.h"
@implementation InfoquestImplementation
-(void):nothing{}
@end
Code for module file of objection
#import "InfoquestTestConf.h"
#import <Objection/Objection.h>
#import "InfoquestViewController.h"
#import "InfoquestImplementation.h"
@implementation InfoquestTestConf
-(void)configure
{
[self bindClass:[InfoquestImplementation class] toProtocol:@protocol(InfoquestProtocolTest)];
}
@end
Code for getting object from objection
JSObjectionInjector *injector = [JSObjection createInjector];
[JSObjection setDefaultInjector:injector];
InfoquestTestConf *Module = [[InfoquestTestConf alloc] init];
[injector withModule: Module];
id<InfoquestProtocolTest> testing2 = [injector getObject:[@protocol(InfoquestProtocolTest)];
但是当我尝试使用 [testing2 nothing] 调用时;我收到错误并且自动完成没有显示任何内容。
谢谢高拉夫