Monday, May 8, 2017

Fast Stuff on a Background GCD Queue

I realize this is not a popular position, but the truth of the matter is that for many (most) situations, you can just do stuff on a background queue and then dispatch the main queue. It's pretty hard (but not impossible) to clog up the main dispatch queue.

NSTimer Replacement: Faster!

Here's my timer for running stuff in the background. Generally, this is all you need. Dispatch to main from within your callback as needed:


Get on Main Queue the Right Way

On the other hand, if you want to do this right and never risk clogging up the main queue, you need to use a dispatch source. See Rob's stuff here on SO, particularly the last part where he discusses a progressIndicator.

GameLoop for MainQueue Dispatch Tied to Frame Rate

On the other hand, if you want something to update every time the main loop goes around, you can use this Game Loop:

Monday, March 20, 2017

Locks with GCD and Swift 3

Even in a Playground it's easy to see how locks work. When useLocks is set to false, a fatal error is thrown before the counter even gets to 5! When it's set to true, the counter can get to its natural endpoint (200).

Saturday, March 18, 2017

Thursday, November 10, 2016