Skip to content

Instantly share code, notes, and snippets.

@kvdesa
Last active April 7, 2021 17:45
Show Gist options
  • Save kvdesa/015062d41785a41ba4ae63688cb2b2c4 to your computer and use it in GitHub Desktop.
Save kvdesa/015062d41785a41ba4ae63688cb2b2c4 to your computer and use it in GitHub Desktop.
Check zombie strings in Xcode project

Check Zombie Strings in Xcode Projects

This script will search for zombie strings, i.e. strings not being used, in an Xcode project.

Original script here

Download it or create it yourself and add it to your user folder.

#!/bin/bash

rootFolder=.
if [[ $1 ]]; then
  rootFolder=$1
fi

allLocalisableFiles=$(find $rootFolder -type f -name "*.strings");
for localisableFile in $allLocalisableFiles; do
  echo -e "\n🔎  Inspecting:" $localisableFile

  while read p; do
    IFS=" = ";
    string=($p);
    key=${string[0]}
    if [[ ${#string[@]} -gt 1 ]] && [[ $key == \"* ]]; then
      if ! grep -rsq --include=\*.{swift,m,h} $key $rootFolder; then
        echo "⚠️ " $key "is not used 💀"
      fi
    fi
    unset IFS;
  done < $localisableFile
done

Add the following code to .bash_profile:

function checkZombieStrings() {
	currentPath="$PWD"
	sudo sh ~/zombie_strings.sh $currentPath
}

Usage

  1. Open the terminal and navigate to your project folder;
  2. Call checkZombieStrings();
  3. Check the terminal for a listing of all zombie strings;
  4. ?
  5. Profit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment