CFRunLoopSource
is cool. It lets you build behavior similar to the mechanisms that drive setNeedsLayout
and setNeedsDisplay
in UIKit.
I found myself in need of something like this a couple of times. It's great to know that no matter how many times I say I need to update something, I will get a single callback at the end of the run loop that gives me a chance to perform my work.
Here is a little Swift wrapper that makes the API easier to deal with.
Updated for Swift 4