Simple guide to Automatic grammar agreement in Swift

Nihal Ismail
2 min readOct 31, 2023

--

1 Apple, 2 Apple, 3 Apple…..

Bet every iOS developer had this embarrassing bug reported at least once in their career and had to deploy a simple fix.

count == 1 ? "\(count) Apple" : "\(count) Apples"

What if there was a more elegant way to handle this? After all, we iOS developers would want our code to look sleek and clean.

Introducing Automatic Grammar Agreement

Using Automatic Grammar Agreement you no longer need to go running around to your localisation files to add plurals wherever necessary in the app. Simply make the following modification.

"^[\(count) Apple](inflect: true)"

Let’s see the following code with SwiftUI in action.

Automatic Grammar Agreement works with String Catalogs and your localisation files across multiple languages which makes it a breeze to develop your iOS apps and mitigate the risk of potential linguistic errors that can arise from manual adjustments. For more exciting and simple guides on iOS Development, Follow me here and on Linkedin.

--

--

Nihal Ismail
Nihal Ismail

Written by Nihal Ismail

 Senior iOS Developer | Architecting and coding high-quality applications that cater to the Apple ecosystem.

No responses yet