Swift
Completed
-
Section 1: Getting Started
-
Section 2: Core Syntax
-
Section 3: Optionals
-
Section 4: Object-Oriented and Value Types
-
Section 5: Memory Management
-
Section 6: Generics and Error Handling
-
Section 7: Concurrency
-
Section 8: Working with Collections
-
Section 9: Codable and Data Handling
-
Section 10: Protocol-Oriented Programming
-
Section 11: Testing and Tooling
-
Section 12: Practical Projects
-
Section 13: Interview Practice
-
Section 14: More Practice Exercises
-
Section 15: More Standard Library
-
Section 16: Advanced Concurrency
-
Section 17: Foundation Framework Deep Dive
-
Section 18: URLSession and Networking Deep Dive
-
Section 19: Combine Framework
-
Section 20: SwiftUI Fundamentals for Swift Developers
-
Section 21: Server-Side Swift with Vapor
-
Section 22: Swift Package Manager Deep Dive
-
Section 23: Swift Concurrency Deep Dive
-
Section 24: More Language Features
-
Section 25: Error Handling Deep Dive
-
Section 26: Testing Deep Dive
-
Section 27: Data Structures and Algorithms in Swift
-
Section 28: More Practice Exercises
-
Section 29: More Interview Practice
-
Section 30: Swift Macros (Swift 5.9+)
-
Section 31: Property Wrappers Ecosystem
-
Section 32: Swift Interop Deep Dive
-
Section 33: iOS App Architecture Patterns
-
Section 34: Performance and Debugging
-
Section 35: App Distribution and CI/CD
-
Section 36: More Practical Projects
-
Section 37: SwiftData and Persistence
-
Section 38: More Design Patterns
-
Section 39: More Review and Practice
-
Section 40: More Foundation Deep Dive
-
Section 41: Advanced Collections in Swift
-
Section 42: Advanced Generics Practice
-
Section 43: UIKit for Legacy and Hybrid Apps
-
Section 44: watchOS and visionOS Development Basics
-
Section 45: More Networking Patterns
-
Section 46: More Testing Practice
-
Section 47: Accessibility in Swift Apps
-
Section 48: Localization
-
Section 49: More Practical Projects Round 2
-
Section 50: Swift Charts Framework
-
Section 51: More Interview and Algorithm Practice
-
Section 52: Final Practice and Mastery
-
Section 53: Swift Compiler and Build System
-
Section 54: More Concurrency Practice
-
Section 55: App Store Guidelines and Review
-
Section 56: More Design and Architecture
208: String Catalogs for Localization
I'll be honest: for years, localization in iOS was a chore. We had to maintain these clunky .strings files, manually typing keys that had to match our code exactly. One typo, and your app just displayed the raw key—like "login_button_title"—to the user. Then there were .stringsdict files for plurals, which were basically XML nightmares that no one wanted to touch.
The headache of manual keys
Let's look at a scenario I'm dealing with right now. I'm building a fitness tracker, and I have a simple view that tells the user how many calories they've burned. Initially, I just wrote it like this:
Text("You burned \(calories) calories today!")
It works in English, but I need this to support Spanish and French. In the old workflow, I'd have to create a Localizable.strings file, manually add "You burned %lld calories today!" = "¡Quemaste %lld calorías hoy!";, and hope I didn't mess up the format specifier. It's tedious and error-prone.
Letting Xcode do the heavy lifting
I want to see if the new String Catalogs can handle this for me. First, I'll go to File > New > File and search for "String Catalog." I'll name it Localizable.xcstrings. At first glance, the file is completely empty. I'm thinking, "Wait, do I still have to type everything in here?"
Actually, no. Here is where the magic happens. I'm going to build my project (Cmd+B). When I check the Localizable.xcstrings file again, the string "You burned \(calories) calories today!" has automatically appeared in the list. Xcode scanned my SwiftUI views, found the Text literals, and pulled them into the catalog for me.
Now, I can just click the "+" button to add Spanish, and I get a nice grid where I can type the translation right next to the original English string. No more jumping between a text editor and a spreadsheet.
Taming the plural nightmare
But here is the real test: plurals. If the user burns exactly 1 calorie, saying "1 calories" sounds robotic and wrong. In the past, I would have had to dive into a .stringsdict file to define "one" and "other" categories. Let's see how the catalog handles this.
I'll right-click the translation key in the String Catalog editor and select "Vary by Plural." Suddenly, Xcode gives me a nested structure. I can now provide a specific translation for the "One" case and a different one for "Other."
- One: "You burned 1 calorie today!"
- Other: "You burned %lld calories today!"
I don't have to write any logic in my Swift code like if calories == 1 { ... } else { ... }. The system looks at the number I passed in and automatically picks the right string from the catalog based on the user's locale rules. This is a massive win for maintainability.
Tracking the gaps
One thing I've always struggled with is knowing exactly what percentage of the app is actually translated. I used to have to search the whole project for untranslated strings. In the String Catalog, I noticed there's a little percentage bar next to each language. As I fill in the Spanish translations, the bar fills up. If I add a new feature with new strings, the bar drops, telling me exactly where I need to go back and add translations. It's a simple visual cue, but it saves me from shipping an app that's half-English and half-Spanish.
📋 Practical Task
Implementing a Localized Workout Summary
You are tasked with adding localization to a "Workout Summary" screen. Instead of hardcoding strings or using old-school strings files, you will implement a String Catalog to handle dynamic content.
Requirements:
- Create a new
.xcstringsfile namedLocalizable.xcstringsin your project. - In your SwiftUI view, implement a
Textview that displays the number of sets completed using a string like:"Completed \(setCount) sets!". - Build the project to ensure the string is automatically extracted into your String Catalog.
- Add "French" as a target language in the catalog.
- Implement Pluralization for the "sets" string in both English and French (handling the difference between 1 set and multiple sets).
- Verify that the translation percentage for French reaches 100% for this specific string.
There are no comments for now.