Reputation: 1287
I have a class called TAPJSONPoster. It's .h is as follows:
#import <Foundation/Foundation.h>
@interface TAPJsonPoster : NSObject
-(id)initWithURL:(NSURL*)url WithJson:(NSData*)jsondata;
-(NSData*)getResponse;
@end
It's .m is:
#import "TAPJsonPoster.h"
@interface TAPJsonPoster()
@property NSURL *url;
@property NSData *jsondata;
@end
@implementation TAPJsonPoster
-(id)initWithURL:(NSURL*)url WithJson:(NSData*)jsondata
{
self=[super init];
self.url=url;
self.jsondata=jsondata;
return self;
}
-(NSData*)getResponse
{
return self.jsondata;
}
@end
I still have tto fill in getResponse, but the init itself is not working. In my ViewController I have
#import "TAPJSONPostConnector.h"
and a method to login:
- (IBAction)loginValidate:(id)sender {
NSString *username=self.unTextField.text;
NSString *password=self.pwdTextField.text;
NSArray *params=[NSArray arrayWithObjects:@"userId",@"password", nil];
NSDictionary *dictionary=[NSDictionary dictionaryWithObjectsAndKeys:
@"_requestName", @"login",
@"_ParamNames", params,
@"userId", username,
@"password", password,
nil];
NSData *data=[NSJSONSerialization dataWithJSONObject:dictionary options:NSJSONWritingPrettyPrinted error:nil];
NSURL *url=[NSURL URLWithString:@"loginURL"];
TAPJSONPostConnector *connector=[[TAPJSONPostConnector alloc] initWithURL:url WithJson:data];
}
The last line where I am making the PostConnector is giving me an error saying that
No @interface in TAPJSONPostConnector declares the selector initWithURL:WithJson
What am I doing wrong?
EDIT I put in [connector getResponse] below the connector initialization and I get the same error for this method also, am I doin something wrong in importing?
Upvotes: 1
Views: 125
Reputation: 40018
Either you're allocating a wrong object TAPJSONPostConnector
instead of TAPJsonPoster
TAPJsonPoster *connector=[[TAPJsonPoster alloc] initWithURL:url WithJson:data];
Or you forgot to change the super class for TAPJSONPostConnector
as TAPJsonPoster
@interface TAPJSONPostConnector : TAPJsonPoster
Change whatever fits your needs
One tip if you can change the name of method initWithURL: withJson:
that will be according to the naming convetion
Upvotes: 1
Reputation: 130222
Well, you're calling the initWithURL:withJson:
initializer on TAPJSONPostConnector
TAPJSONPostConnector *connector=[[TAPJSONPostConnector alloc] initWithURL:url WithJson:data];
But it looks like this is declared on the TAPJsonPoster
class. Perhaps this is what you meant.
TAPJsonPoster *connector=[[TAPJsonPoster alloc] initWithURL:url WithJson:data];
Upvotes: 2