I've defined a class called 'AsyncNetworkOperation', a subclass of NSOperation used to perform database queries in my app. My AsyncNetworkOperation class has a protocol, to be used by objects that initiate the AsyncNetworkOperation:
@protocol AsyncNetworkOperationDelegate
@optional - (void)operationAboutToFinish;
@required - (void)operationFinishedWithData:(id)retrievedData;
@required - (void)operationFinishedWithError:(NSError*)error;
@end
This all works fine, except in the case where the delegate I'm calling back to wants to show a UIAlertView, start an NSTimer, or do something else that secondary threads either aren't supposed to do, or require extra effort to do.
So here's my question: when I callback to the delegate, should I do so via -[NSObject performSelectorOnMainThread:]? It would seem that in doing so, I relieve my delegate from the burden of having to know whether it's being called back via a secondary or primary thread, thereby allowing it to implement functionality in the most straightforward way possible, with no limitations.
Just wondering about the standard way to approach this problem.
Thanks.