Archive for June 6, 2016

Monday, June 6, 2016

GCD’s Main Queue vs. Main Thread

Benjamin Encz (tweet):

Technically I think this is a MapKit / VektorKit bug, Apple’s UI frameworks typically guarantee to work correctly when being called from the main thread, no part of the documentation mentions that code needs to be executed on the main queue.


By combining GCD and Cocoa’s NSThread API we are drilling through the abstraction that GCD should provide in the first place. APIs that fully rely on GCD and ignore the presence of the underlying threads can run into problems if you call them on the main thread but not the main queue. This means, especially when calling into other frameworks, we should prefer using dispatch_queue_set_specific and dispatch_get_specific to check if our code is running on the main queue over using NSThread.isMainThread().

It’s hard to get this right because of reentrancy, though.

Avoiding the Overuse of @objc in Swift

Swift 2.2’s #selector syntax introduces a new compiler error:

Argument of '#selector' refers to a method that is not exposed to Objective-C.

Fix-it   Add '@objc' to expose this method to Objective-C

Jesse Squires:

We cannot simply add @objc to this method in the original ViewControllerType protocol for a number of reasons. If we do, then the entire protocol needs to be marked @objc, which means[…] Our example here is simple, but imagine a much more complex object graph that makes heavy use of Swift’s value types and a hierarchy of three protocols with this one in the middle. Introducing @objc as the fix-it suggests would break the entire world in our app.


We can decompose this protocol by separating out all of the @objc code into its own protocol. Then, we can use protocol composition to reunite them.

Converting Old Videotapes

David Pogue:

As it turns out, YesVideo and Costo (and Walmart and CVS) are the same thing. (YesVideo “white labels” — secretly does the work — for those other chains.)

Southtree does its own work out of a 40,000 square-foot production facility in downtown Chattanooga, Tennessee. They have over 1,000 playback machines. I liked what I read on its site.


What’s really odd is that Southtree, YesVideo and other competitors seem hell-bent on converting your old tapes to DVDs. […] What I wanted, of course, was for all of the video to be put onto a hard drive or flash drive, but none of that is available on Southtree’s price list (or YesVideo’s).

Nick assured me, though, that they do offer this service. If that’s what you want, you sign up for the DVD conversion and then type something like, “copy to the drive I’ve supplied” in your order notes.