(Resending since I accidentally sent the first one from the wrong e-mail 
address. Please reply to this one instead of the other to avoid re-posting my 
private e-mail address to the list, where it will be vulnerable to spambots. 
Thanks!)

On Jan 22, 2013, at 1:38 PM, Rick Aurbach <r...@aurbach.com> wrote:

> Thank you for the explanation. I only started learning Objective-C, Cocoa, 
> iOS, etc in August, so I'm still pretty much a newbie and appreciate learning 
> something new.
> 
> In this particular case, the selector that is the argument to the 
> performSelector: method is a callback selector for NSTimer and hence is known 
> to return void. Therefore, using the #pragma to turn off this message is safe.
> 
> Thanks for the insight.

I'd still use GCD instead. Not only do you not need a #pragma, but you also get 
compile-time checking that will warn you if the method you're calling ever gets 
changed or removed. Using @selector can be a huge pain when the selector it 
refers to gets renamed or removed — the compiler doesn't check @selector at 
all, so everything will seem fine until you start noticing exceptions and 
crashes at runtime.

Plus, it's less code. Here's a timer in GCD:

int64_t delayInSeconds = 2;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * 
NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
   [foo doSomethingWith:bar];
});

And, the first three lines of that code is auto-completed for you as soon as 
you start typing "dispatch_after" in Xcode, so the only thing you actually have 
to write is the contents of the block of code that should run when the timer 
fires (well, and changing the 2 to whatever time interval you're going for). No 
passing around selectors, no packing extra info into the timer's userInfo, no 
implementing a separate method to run when the timer fires. Simple and 
straightforward.

Charles
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to