• 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: Why RunLoop?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why RunLoop?


  • Subject: Re: Why RunLoop?
  • From: Nick Zitzmann <email@hidden>
  • Date: Mon, 16 May 2011 09:25:57 -0600

On May 16, 2011, at 9:07 AM, Bing Li wrote:

> Dear all,
>
> I am a new programmer of Cocoa. When learning RunLoop, I felt a little bit
> weird. Why should Cocoa provide such a technique? When programming on other
> environments, a while-true loop and wait/pulse lock can be used to achieve
> the same goal of RunLoop, right?

Well, yes, pre-Carbon Classic Mac OS forced programmers to write their own run loops by polling for events, but why do that when there's code already written for you?

> I notice that Cocoa threading can be programmed in the similar way. May I
> ignore RunLoop?

Only if you're doing some task that will start and exit, and doesn't have to handle events or timers or notifications. Otherwise, you need a run loop. NSApplication and UIApplication will run the main thread's run loop automatically. But if you, for instance, attach a timer to the run loop of another thread, then you need to run that thread's run loop or the timer will not trigger.

Nick Zitzmann
<http://www.chronosnet.com/>

_______________________________________________

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: Why RunLoop?
      • From: Ken Thomases <email@hidden>
References: 
 >Why RunLoop? (From: Bing Li <email@hidden>)

  • Prev by Date: Why RunLoop?
  • Next by Date: Re: NSPostWhenIdle not doing its job?
  • Previous by thread: Why RunLoop?
  • Next by thread: Re: Why RunLoop?
  • Index(es):
    • Date
    • Thread