Give your simulator superpowers

RocketSim: An Essential Developer Tool
as recommended by Apple

Unused localized strings clean up from a Strings file

Strings files are used for localization in iOS and MacOS apps. These files can grow over time and make it hard to maintain. It’s easy to end up with a lot of unused localized strings. Although this is not an issue for performance or slowing you down a lot, it is kind of nice to keep your resource files clean.

Xcode does not provide an out of the box solution for this. However, we have a great community and quite some tools exist to solve this issue. I dived in and took a look at NSLocalizerAbandoned Strings, and this medium blog post. From the two Github projects, the one from Josh Smith gave the best results.

Before we dive in, it’s worth mentioning that the medium blog post from Gino Wu provides a nice way to integrate it into your Xcode build process. However, in my opinion, this is not something you need to integrate and run that often, slowing down your build process for each run. It’s unlikely that you end up with unused strings quite often, so running it manually every now and then should be enough.

Therefore, let’s dive into the Abandoned Strings terminal tool.

The tool will show a list of unused localized strings after running the command

Finding unused resource strings

The first step is to create an executable from the Github project. Download the project from github.com/ijoshsmith/abandoned-strings, build it by using Xcode and find the executable in the products folder.

Show the containing folder in Finder

The executable to use for finding unused localized strings

Right-click on the executable and select “Show in Finder” to open the containing folder. This will be your base path to use in the terminal. You can use the cd  command to change the terminal directory. After that, run the following command:

$ ./AbandonedStrings /Users/your-username/path/to/source/code

Removing unused localized strings

The tool will show a list of unused localized strings after running the command:

A list of unused localized strings

A list of unused localized strings in the results after running the command

You can use this list to remove them from your project. Unfortunately, this is still a manual process and can be quite some work if you have a lot of unused strings. However, this will improve if you run this tool more often.

What is included in the results?

The tool takes .strings files in your project and walks through all defined keys. Say that the strings file contains a key called home.button.title. The tool will take this key and validates whether any .h, .m.swift or .jsbundle contains a reference. If not, it will consider that key as unused.

What else?

Although this tool is great to keep your string files clean, you have to run it manually yourself and remind yourself to run it every now and then. However, as you’re unlikely to introduce unused strings quite often, it’s more than fine to not run it every day.

 

Stay Updated with the Latest in Swift & SwiftUI

Let me do the hard work and join 18,250 developers that stay up to date using my weekly newsletter:


Featured SwiftLee Jobs

Find your next Swift career step at world-class companies with impressive apps by joining the SwiftLee Talent Collective. I'll match engineers in my collective with exciting app development companies. SwiftLee Jobs