Re: Sublclassing NSThread
Re: Sublclassing NSThread
- Subject: Re: Sublclassing NSThread
- From: "Bradley S. O'Hearne" <email@hidden>
- Date: Tue, 16 Dec 2008 15:19:58 -0700
All,
Thanks to everyone for the replies. In my code, I made an error --
overrode the start method rather than the main method. After I
overrode the start method, everything worked great. Without trying to
get too specific on the actual issue, the more general thrust of my
original question was getting at encapsulating a piece of
functionality that needs asynchronous execution (i.e. within a
separate thread from the main thread) within an NSThread subclass. The
reason this is useful is that rather than have this code scattered
within an application which needs it, I can instead make a generic
utility class out of it (which I've now done) and can reuse it
anywhere. In my case, I was creating code to asynchronously load a
large number of remote images (located on a server) within my
application.
Thanks again,
Brad
On Dec 16, 2008, at 12:29 PM, Shawn Erickson wrote:
On Tue, Dec 16, 2008 at 9:29 AM, Brad O'Hearne
<email@hidden> wrote:
Hello,
I am trying to create an NSThread subclass which completely wraps the
desired behavior of the thread execution.
I am sorry but what you described isn't making sense to me so I really
don't know how to answer your question. Can you restate it?
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
Inside of any instance method "self" exists (hidden parameter to the
method call) and points to the instance that received the message. In
"init" methods you do the self = [super initXxxx]; to deal with the
super implementation possibly swapping the original instance out for
another instance (see Cocoa does on initializers).
If you sub-class NSThread you override -main to provide the
implementation for the code that will run in the thread context. I am
not sure why you want/think you need to override -start.
-Shawn
_______________________________________________
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