Finding unused files in Xcode

前端 未结 6 924
生来不讨喜
生来不讨喜 2021-02-18 18:52

I\'ve recently started work on a new app which is basically a copy of a previous app I made, with a few changes. To make this new app I\'ve copied the old app and removed some s

相关标签:
6条回答
  • 2021-02-18 19:14

    There isn't any functionality like this built into Xcode, but the issue of unused classes/files etc isn't as simple as one may think.

    People have created scripts to try and determine unused files. I have used the script located here, which searches through all your source files, and tries to pair up the resource files. The script also tries to check for source files not included within your project.

    The reason its not so trivial is that Obj-C is a very dynamic language; a lot of things are determined at run-time. As such, it sometimes can be tricky to figure out unused files statically. For example, an image name might be determined on the fly depending on user input.

    I don't know how big your application is, but you could try a dependency graph, and check for orphan classes. See this blog post on some more information.

    0 讨论(0)
  • 2021-02-18 19:16

    See the useful tool. A Mac app for checking Xcode projects for unused resources http://jeffhodnett.github.io/Unused/

    0 讨论(0)
  • 2021-02-18 19:19

    There's an app called Slender by Martiancraft that is good for suggesting potentially unused images.

    http://martiancraft.com/products/slender.html

    I believe that Faux Pas does something similar for class files, but I will check. That app does also look for unused methods, translations and resources.

    http://fauxpasapp.com/rules/#rule-UnusedResource

    I haven't used either app recently, but can remember being impressed with both previously.

    0 讨论(0)
  • 2021-02-18 19:25

    Also see this shell scripts http://mfaizanshaikh.wordpress.com/2012/12/17/how-to-remove-unused-images-from-xcode-project/

    Basically the shell script below, finds all the png files in your project that are not used in any of the xib files. Of course if you have used the png file in other ways (storyboards, load in the code), this script will still show them as unused.
    for reference I paste the scripts here as well:

    #!/bin/sh
    PROJ=`find . -name '*.xib' -o -name '*.[mh]'`
    
    for png in `find . -name '*.png'`
    do
        name=`basename $png`
        if ! grep -q $name $PROJ; then
            echo "$png is not referenced"
        fi
    done
    
    0 讨论(0)
  • 2021-02-18 19:27

    This tool finds unused imports/classes: fui.

    From the README page:

    Find unused Objective-C imports.

    0 讨论(0)
  • 2021-02-18 19:32

    The AppCode IDE from Jetbrains has some very decent code inspection functions. It can point out unused classes and other resources, and claims to be fully Xcode compatible.

    0 讨论(0)
提交回复
热议问题