• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How can I get rid of this warning message?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How can I get rid of this warning message?


  • Subject: Re: How can I get rid of this warning message?
  • From: Charles Srstka <email@hidden>
  • Date: Tue, 22 Jan 2013 14:34:47 -0600

(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 <email@hidden> 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 (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


  • Follow-Ups:
    • Re: How can I get rid of this warning message?
      • From: David Duncan <email@hidden>
References: 
 >How can I get rid of this warning message? (From: Rick Aurbach <email@hidden>)
 >Re: How can I get rid of this warning message? (From: Greg Parker <email@hidden>)
 >Re: How can I get rid of this warning message? (From: Rick Aurbach <email@hidden>)

  • Prev by Date: Re: object.struct.element as lvalue
  • Next by Date: Re: How can I get rid of this warning message?
  • Previous by thread: Re: How can I get rid of this warning message?
  • Next by thread: Re: How can I get rid of this warning message?
  • Index(es):
    • Date
    • Thread