Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: self and _cmd



> From: Ondra Cada <email@hidden>
> Date: Thu, 6 Sep 2001 11:03:33 +0200
> To: Chris Kane <email@hidden>
> Subject: Re: self and _cmd
> Cc: Cocoa-dev List <email@hidden>
> Reply-To: email@hidden
>
> Chris,
>
> >>>>>> Chris Kane (CK) wrote at Wed, 5 Sep 2001 14:06:35 -0700:
> CK> >-(void)notWorthUsingNSTimer {
> CK> >...
> CK> >[self performSelector:_cmd withObject:nil afterDelay:delay];
> CK> >}
> CK>
> CK> Ha! the implementation will show you what's not worthwhile. :-)
> CK>
> CK> -performSelector:withObject:afterDelay: simply creates an
> NSTimer...
>
> Oh my. Who cares of implementation? "not worth" was naturally meant
> "from
> the programmer's viewpoint, since it's simpler and quicker and
less
> error-prone to use" (in simple situations).
>
> CK> The odd thing about this example is that you're scheduling
> CK> "notWorthUsingNSTimer" to execute later, which is probably not
what
> you
> CK> want, since it'll apparently result in an infinite, if slowly,
and
> CK> "out-of-bandedly", executed, loop. :-)
>
> It's very exactly what I wanted. It's the way to do eg. polling
whenever
> it
> is really needed. Also it's the way to do "idle events".

What about using NSNotificationQueue to post a notification to
yourself using NSPostWhenIdle? Seems cleaner to me than having your
app do stuff on a timed interval.

Of course, shoving all your background processing cack into a
separate thread is the real solution in most cases. I can't think of
a case where I'd want 'idle processing' to occur in the foreground.

Simon

--
If the answer isn't obvious, the question is a distraction. Go find
an
easier question.




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.