我创建了一个单例来执行一些服务器请求。但是对于某些请求,我需要返回结果。从调用类中获取它们的最佳方法是什么(使用单例)?
这是接收数据时单例的调用方法。我应该将目标和选择器传递给单例来执行调用者类的方法吗?
- (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];
}
感谢
答案 0 :(得分:3)
在委托中传递本地通知比接收调用者类的选择器更好。该本地通知可以由注册它的任何人处理,从而最小化依赖性。