Edit: If you want the delegate callbacks to occur on the main thread, use this pattern:
[delegate performSelectorOnMainThread:@selector(threadDidSomething:) withObject:self waitUntilDone:NO]
Here you go. I believe this is self-explanatory, but if not, just let me know. Please note: I just wrote this code based on the API, but have not tested it, so take caution.
@protocol ThreadLogicContainerDelegate <NSObject>
- (void)threadLogicContainerDidStart:(ThreadLogicContainer*)theThreadLogicContainer;
- (void)threadLogicContainerDidFinish:(ThreadLogicContainer*)theThreadLogicContainer;
@end
@interface ThreadLogicContainer
- (void)doWorkWithDelegate:(id<ThreadLogicContainerDelegate>)delegate;
@end
@implementation ThreadLogicContainer
- (void)doWorkWithDelegate:(id<ThreadLogicContainerDelegate>)delegate
{
@autoreleasepool
{
[delegate threadLogicContainerDidStart:self];
// do work
[delegate threadLogicContainerDidFinish:self];
}
}
@end
@interface MyDelegate <ThreadLogicContainerDelegate>
@end
@implementation MyDelegate
- (void)threadLogicContainerDidStart:(ThreadLogicContainer*)theThreadLogicContainer
{}
- (void)threadLogicContainerDidFinish:(ThreadLogicContainer*)theThreadLogicContainer
{}
@end
Sample usage:
ThreadLogicContainer* threadLogicContainer = [ThreadLogicContainer new];
[NSThread detachNewThreadSelector:@selector(doWorkWithDelegate:)
toTarget:threadLogicContainer
withObject:myDelegate];
reference: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSThread_Class/Reference/Reference.html