我有一个单独的类,我想处理来自 ASIHTTPRequest 的响应,所以我创建了一个类的实例,然后将它传递给我的请求。问题是我的委托类在请求完成之前被释放。
我正在使用ARC。如何确保为 didFinish/didFail 选择器保留委托?
-(void)getStuff
{
NSURL *url = [NSURL URLWithString:@"http://example.com/json"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
UpdateFeedDelegate *updateFeedDelegate = [[UpdateFeedDelegate alloc] init];
[request setDelegate:updateFeedDelegate];
[request setDidFinishSelector:@selector(updateTestDone:)];
[request setDidFailSelector:@selector(getSingleUpdateFeedBackgroundRequestFailed:)];
[request startAsynchronous];
}
在示例中,选择器类按预期存在。我得到错误:
*** -[UpdateFeedDelegate respondsToSelector:]: message sent to deallocated instance 0x56efb50
*** NSInvocation: warning: object 0x56efb50 of class '_NSZombie_UpdateFeedDelegate' does not implement methodSignatureForSelector: -- trouble ahead
*** NSInvocation: warning: object 0x56efb50 of class '_NSZombie_UpdateFeedDelegate' does not implement doesNotRecognizeSelector: -- abort