Today’s WTF moment with Swift is related to switch-case and the pattern matching operator, ~=
. Defining operator overloads for special cases can help to keep case
statements readable. And I thought it’d be simple enough to quickly check the setup, but I was in for a surprise!
Continue reading …
Today, I had trouble getting NSColor
to work with colors from Asset catalogues when asking for its .cgColor
. Since NSColor
is appearance-aware, i.e. it switches light and dark mode appropriately when used directly in your views, I wondered why asking for .cgColor
always returned the initial value. Say we start the app in light mode, then this is always going to be the light mode color, never dark mode. Yes, not even if you initialize the color anew using NSColor(named: ...).cgColor
.
Continue reading …