XCode will not recognize custom method
I have a custom NSObject class called "GREST", everything works aside from this method. Auto completion won't even recognize it, and I honestly can't figure out why. I've tried changing the method's name and everything. When I call the method, it works, I just get the warning that the class may not respond to this method.
I have this method declared in my header file
- (void)connect:(NSString *)connection_url parameters:(NSString *)parameter_string header:(NSString *)header_type
And here is the implementation
- (void)connect:(NSString *)connection_url parameters:(NSString *)parameter_string header:(NSString *)header_type {
NSData *request_data = [parameter_string dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *request_length = [NSString stringWithFormat:@"%d", [request_data length]];
response_data = [[NSMutableData alloc] init];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:connection_url]];
[request setHTTPMethod:@"POST"];
[request setValue:request_length forHTTPHeaderField:@"Content-Length"];
if([header_type isEqualToString:@""] || header_type == nil || header_type == NULL) {
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
} else {
[request setValue:header_type forHTTPHeaderField:@"Content-Type"];
}
[request setHTTPBody:request_data];
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[request setTimeoutInterval:10];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
if(!connection) {
[self apicall_failed];
}
[connection release];
}
When I try to call this method, XCode gi开发者_如何学运维ves me the following warning
'GREST' may not respond to '-connect:parameter_string:header_type:'
Edit, here's how the code is being called:
GREST *api = [[GREST alloc] init];
[api setDelegate:self];
[api connect:@"http://domain.com" parameter_string:@"{'username':'hi'}" header_type:@"application/json"];
[api release];
Everything works fine, but I'm just trying to get rid of this warning now. Any ideas on how I can do this? Thanks in advance!
compare the method names:
'-connect:parameter_string:header_type:'
to
'-connect:parameters:header:'
the difference is that you are using the names of the method's arguments, not the actual method/selector. this will result in a runtime exception when called.
the compiler will tell you the line where you try to use the former, and xcode will probably highlight the line.
Change
[api connect:@"http://domain.com" parameter_string:@"{'username':'hi'}" header_type:@"application/json"];
to
[api connect:@"http://domain.com" parameters:@"{'username':'hi'}" header:@"application/json"];
精彩评论