Skip to content

Instantly share code, notes, and snippets.

@hsleedevelop
Last active May 14, 2019 02:13
Show Gist options
  • Select an option

  • Save hsleedevelop/4d29c0fd212ed1569779e0444ebf59b1 to your computer and use it in GitHub Desktop.

Select an option

Save hsleedevelop/4d29c0fd212ed1569779e0444ebf59b1 to your computer and use it in GitHub Desktop.
find not using files in Xcode project
https://stackoverflow.com/a/52825714/3374327
Assuming your MyProject.xcodeproj is in your working directory, and all your sources are in or below your working directory, you could use a hack* like this to look for .m files that are not part of any target:
find . -name "*.m" -exec basename '{}' \; | xargs -I '{}' sh -c 'grep "{} in Sources" MyProject.xcodeproj/project.pbxproj > /dev/null; echo "$?\c"; echo " {}"' | grep "^1"
Once you remove the files from the project, you can remove them -- and other objc source files that are no longer referenced from your project -- from your git repo using this similar script:
find . -name "*.[hm]" -exec basename '{}' \; | xargs -I '{}' sh -c 'grep {} MyProject.xcodeproj/project.pbxproj > /dev/null; echo "$?\c"; echo " {}"' | grep "^1" | cut -c3- | xargs -I '%' find . -name '%' -exec git rm '{}' \;
* hack in the sense that it depends on implementation details of the Xcode file format.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment