Sublclassing NSThread
Sublclassing NSThread
- Subject: Sublclassing NSThread
- From: Brad O'Hearne <email@hidden>
- Date: Tue, 16 Dec 2008 10:29:45 -0700
Hello,
I am trying to create an NSThread subclass which completely wraps the
desired behavior of the thread execution. Now typically when creating
a new thread instance, it seems one will use the
initWithTarget:selector:object initializer to properly direct the
thread's execution. But what if I want the thread subclass to invoke a
method within itself? This leaves you with a situation where you have
to set the target to self within the initializer, but that seems
problematic, as "self" is not yet defined, i.e.:
- (id)init {
self = [super initWithTarget:self @selector(myMethod) object:nil];
return self;
}
As you can see, the initWithTarget: param is set to self, but the
purpose of that statement is to set self, and self isn't defined yet
to my knowledge. I'd otherwise just use the NSThread's init method,
but I do not see a way to set the target as a property on the thread
object once initialized. So my question is, in Objective C, is the
typical approach to wrapping behavior entirely within an NSThread
subclass to override the start method, as such:
- (void) start {
[super start];
[self myMethod];
}
Is this the recommended approach, or is there another way to go about
this?
Thanks,
Brad
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden