0
使用ASIHTTPRequest爲我們的其餘api構建api。如何將附加參數傳遞給ASIHTTPRequest didFinishSelector選擇器
Api將所有請求包裝到它自己的方法中。
- (void) foo:(id)caller
andSuccessCallback:(SEL)successCallback
andFailureCallback:(SEL)failureCallback {
_currentCaller=caller;
_currentSuccessCallback=successCallback;
_currentFailureCallback=failureCallback;
NSString *urlString = @"http://localhost/foo";
NSURL *url= [NSURL URLWithString: urlString];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request setDidFinishSelector:@selector(fooSuccess:)];
[request startAsynchronous];
}
- (void) fooSuccess:(ASIHTTPRequest *)request {
if (statusCode >=400) {
if ([_currentCaller respondsToSelector:_currentFailureCallback])
[_currentCaller performSelector:_currentFailureCallback withObject:statusCode withObject:message];
} else {
if ([_currentCaller respondsToSelector:_currentSuccessCallback])
[_currentCaller performSelector:_currentSuccessCallback];
}
[request release];
}
目前通過回調選擇我使用類私有變量_currentCaller _currentSuccessCallback _currentFailureCallback = failureCallback
我可以把它們傳遞給直接fooSuccess回調?