0

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

user1394622
  • 67
  • 1
  • 10

3 Answers3

3

You have a syntax error:

You should replace:

-(void):nothing;

with

-(void)nothing;
gWiz
  • 1,274
  • 9
  • 12
1

here is an error in your syntax.please change :

    -(void):nothing;

to:

    -(void)nothing;
Imran Ahmed
  • 1,023
  • 1
  • 11
  • 23
0

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.

Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56
  • Please explain a bit more i am novoice in custom delegates, i know delegates as they are implemented in tableviewcontroller. – user1394622 Oct 14 '13 at 09:55
  • Custom delegates are nothing just you are writing your own delegate with your define method inside protocol. And also when you define the method inside your protocol then you have to implement the same in another class where you wan to use – Hussain Shabbir Oct 14 '13 at 09:59
  • http://stackoverflow.com/questions/645449/how-to-use-custom-delegates-in-objective-c please follow this link – Hussain Shabbir Oct 14 '13 at 10:04