Code and Crumpets

Coding, Thoughts and Sourdough

British Swift Syntax šŸ‡¬šŸ‡§

If you’ve ever winced at the sight of Color instead of Colour, or felt despair reading try…catch when a good old ā€œWould you mind…?ā€ would be spot on, then this one’s for you.

I’ve put together a small, but fit and proper set of Swift tidbits that clean up the more questionable Americanisms in our lovely codebases. It’s a tiny rebellion. A syntax protest. A quiet sip of tea in the face of UIColor.

You can find the code featured in this article in full on GitHub here:

šŸ‘‰ https://gist.github.com/SandorUK/c4d0d094ffb8adc32316a70053e1accf

Let’s have a butcher’s, shall we?

šŸ«– Colour.swift – Because we spell it with a u

typealias Colour = Color

That’s it. This puts things right. Every time you write Colour, you’re sticking it to the red-white-and-blue spelling checker.

But I didn’t stop there. This file goes full spectrum on UIKit’s colours too, mapping UIColor.systemRed and friends into the Colour type with proper SwiftUI integration:

static let systemMint = Colour(UIColor.systemMint)

All in properly titled British spelling. Because independence was a mistake.

šŸ¤” Perhaps.swift – A gentler, more polite if

Why must control flow be so insisting? So abrupt? Enter perhaps.

perhaps(isRaining) {
    print("Don’t forget your umbrella!")
} otherwise: {
    print("Looks like a cloudy day. Stay cozy indoors!")
}

A gentle suggestion, not a cold demand. And none of that if this or else that, that, frankly, sounds like a threat.

šŸ˜… WouldYouMind.swift – Swift error handling with manners

Instead of this:

do {
    try something()
} catch {
    handle(error)
}

Try this:

wouldYouMind {
    try doSomethingRisky()
} actuallyIdoMind: { error in
    print("Actually, I do mind: \(error.localizedDescription)")
}

Because nothing says ā€œunexpected runtime failureā€ like pretending you’re fine with it until you’re not.

Why?

Let’s be honest: Americanisms are the base of code syntax and are everywhere, and fair play to them – it’s Apple’s language after all. But if you’re from the UK (or just a fan of proper and not simplified English), these little tweaks make your project feel more… you.

Plus, your code starts to read like a conversation rather than a set of instructions barked at a compiler.

Install

No Cocoapods, no SPM. Just drop or outright copy the .swift files into your project and start writing Swift with a cuppa in hand.

You’ll find:

• Colour.swift ā€“ For system colours with a u

• Perhaps.swift ā€“ If/else, but softer

• WouldYouMind.swift ā€“ Error handling, politely

Grab them here:

šŸ‘‰ British Swift Gists – GitHub

Future plans

I’m toying with the idea of adding whilst, shallWe, and ohDear. Maybe even haveAQuickLookAt.

Let me know if you’ve got any ideas or want to collaborate on a Swift Package that brings proper British values to modern codebases. We could call it BritKit or SwiftTea.

Fediverse Reactions