Collection enumeration performance in Swift

Swift’s Collection and Sequence protocols provide two primary ways to enumerate (filter, map, reduce, etc): functional-style and imperatively. For example: Or: Nominally these are equivalent – they’ll produce the same results for all correctly-implemented Collections and Sequences. So in principle which you use is purely a matter of stylistic preference. But is it? Do they… Read more

Performing a delayed and/or repeating operation in a Swift Actor

Say you want to perform some operation after a delay, and/or at regular intervals, inside a Swift actor – maybe your actor represents a weather station and you want to periodically fetch the latest weather information, automatically. How do you do that? You could punt the problem to some other code, outside the actor –… Read more

Swift on Raspberry Pi

After the horrible experience just acquiring, installing, & configuring a basic Raspberry Pi, I was anticipating much effort – likely ending in failure – to get Swift working. I was pleasantly surprised. There are multiple ways to do it, apparently. One would think that there’d be the correct & working packages already available through apt,… Read more

‘Fake error’ about immutable values when using popFirst() on Array

It’s been a while since I wrote any meaningful Swift.  How I didn’t miss the Swift compiler’s bullshit error messages. That yields, on the popFirst() method: Cannot use mutating member on immutable value: ‘someArray’ is immutable. No it’s not.  It’s simply not. For whatever reason, if you instead call popFirst() on ArraySlice – ostensibly indistinguishable from… Read more

Undocumented Swift conditional compilation macros

swift/lib/Basic/LangOptions.cpp has most of the conditional compilation macros (called “Language Options” in the compiler internally).  Notably the swift() version macro is absent, and doesn’t seem to be defined anywhere… At time of writing the two undocumented additions, to the os(), arch(), and swift() set, are _endian() and _runtime(). I have no idea if they’re useful… Read more

#if DEBUG in Swift

Sigh. The Swift team give an impeccable impression of a group of people who’ve never actually tried to use Swift. An incredibly basic compiler task is to provide code a way to distinguish between debug & release builds, in order that it can behave accordingly (e.g. change the default logging verbosity, change asserts from fatal to… Read more