我创建了一个单例来执行一些服务器请求。但是对于某些请求,我需要取回结果。从调用类(使用单例)获取它们的最佳方法是什么?
这是接收到数据时由单例调用的方法。我是否应该将目标和选择器传递给单例以执行调用程序类的方法?
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// do something with the data
//invoking passed selector here ?
// receivedData is declared as a method instance elsewhere
NSLog(@"Succeeded! Received %d bytes of data",[receivedData length]);
// release the connection, and the data object
[connection release];
[receivedData release];
}
谢谢
最佳答案
在委托(delegate)内部传递本地通知比接收调用类的选择器要好。该本地通知可以由注册它的任何人处理,从而最大限度地减少依赖性。
关于objective-c - 关于单例和调用方法的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7241814/