Writing

Hey, You! Let’s Talk TypeLocXC: A Swift Dev’s Adventure

Hey there, fellow coder! Ever had your coding sidekick flake out mid-project while Apple lobs shiny new curveballs your way? That was me, a mid-level iOS dev obsessed with type-safe code, especially for those sneaky localised strings. SwiftGen was my ride-or-die… until Apple dropped the xcstrings bomb. Cue the chaos, and my wild ride to fix it.

Originally published on Medium.

An illustration of a developer with a backpack climbing broken scaffolding towards a Union Jack, past crates marked Swift.
A Journey of a thousand prompts

The Problem: SwiftGen vs. xcstrings

So, here’s the deal. The xcstrings format is chef’s kiss brilliant. Structured dictionaries for pluralisation, parameterised strings, and even warnings if your localisation’s a bit dodgy. It’s like Apple said, “Let’s make this less of a faff,” and I was all in.

But SwiftGen? It wasn’t vibing with xcstrings. I was torn: stick with SwiftGen’s compile-time safety or dive into xcstrings’ modern glow. Why not both? Spoiler: I made it happen.

xcstrings aren’t just Apple’s latest buzzword; they’re a lifeline.

Imagine juggling plurals like ‘1 cat’ vs. ‘2 cats’ without writing a maze of if-statements. Or passing parameters into strings without duct-taping it all together. For devs, it’s less spaghetti code; for translators, it’s context galore, with no more guessing if ‘Play’ is a button or a theatre reference. It’s localisation that doesn’t make you want to chuck your Mac out the window.”

The Solution: Enter TypeLocXC

Refusing to compromise, I rolled up my sleeves and birthed TypeLocXC: a nifty little tool that brings type-safe goodness to xcstrings. It’s lightweight, it’s modern, and it keeps your localised strings in check without sacrificing that sweet, sweet safety.

Job done? Not quite. The journey was a riot.

The Journey: A Coding Jungle Odyssey

First, I turned to AI. “ChatGPT and Grok will save me!” I thought. Big nope. ChatGPT churned out a Swift Package that looked slick, until it tried importing MagicLocalizationKit, a ghost library from nowhere. I begged, “No, xcstrings!” and got a syntax error stew. Grok? It gifted me a haiku about structs. Cute, but I’m not framing it.

AI’s just fancy autocomplete: great for snippets, useless for a full-on Swift Package. The training data’s too thin for real-world tools.

So, I cracked open the Swift Package Manager docs. Blimey, it’s denser than a Tolkien novel: no pictures, just walls of text. I slogged through, nearly lost my mind, then stumbled on carlynorama’s blog post on swift.org. A working example! Carly, the Swift team, and the unsung heroes of blogs and forums pulled me from the abyss. Community FTW.

Oh, and the GitHub grind? Brutal. SPM quirks, tags, releases: it’s a gauntlet. I emerged with TypeLocXC, a head full of Package.resolved dreams, and a newfound respect for version control and how to distribute versioned packages.

The Result: TypeLocXC in Action

Swift’s toolchain is a bustling city. SwiftUI’s the glitzy skyline, but tools like TypeLocXC are the sturdy bridges. As apps grow (more languages, more strings), type safety’s your lifeline. A typo in a key can crash your build or baffle users. TypeLocXC’s got you covered.

Before TypeLocXC:

let greeting = NSLocalizedString("welcome_message", comment: "Welcome text") // Typo bait, no autocomplete, hope it’s in the strings file

After TypeLocXC:

swift let greeting = L10n.Welcome.message // Safe, slick, sorted

Night and day, right?

Wrap-Up: Your Turn!

There it is: TypeLocXC, my gift to type-safe xcstrings lovers. Hate localisation chaos? Crave clean code? It’s live, open-source, and begging for your touch. Fix a bug, drop a feature, or just star it; every move makes life better for devs worldwide. Plus, you’ll flex your SPM chops. Let’s make it legendary!

Dive in: https://github.com/JohnnyD1776/TypeLocXC

Till the Next Byte,

British Dev’s Diary

All writing