Reputation: 67
I am new to objective C and trying to implement objection (dependency injector).
But its not working below is the code i am using
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)];
But when i try to call using [testing2 nothing]; i am getting error and autocomplete doesnt show up nothing.
Thanks gaurav
Upvotes: 0
Views: 304
Reputation: 1033
here is an error in your syntax.please change :
-(void):nothing;
to:
-(void)nothing;
Upvotes: 1
Reputation: 1284
You have a syntax error:
You should replace:
-(void):nothing;
with
-(void)nothing;
Upvotes: 3
Reputation: 15015
Hence you are using custom delegates. So first you have to set the delegate to your class where you are implementing the method of your protocol.
Upvotes: 0