Delete unused images in the ios project using scripts.

Source: Internet
Author: User

Delete unused images in the ios project using scripts.

I recently learned a major trick in reading Tang Qiao's "iOS development advanced": using scripts to delete unused images in ios. (there is a small problem in the paper. Refer to the issue on github: delete unused images in ios using scripts ).

We recommend that you save the code in A. sh file and execute the shell script file in xcode. I can see that the beginning is very big, and the university's shell is returned to the linux teacher... how can I execute the script in xcode ???

Google it and find the method to create a. sh file on mac: Teach you to create executable script files on mac. Of course, there are three methods to execute scripts in XCode. The following is a summary of this operation:

1. Create an executable script file:

(1) Open sublime and enter the following shell code:

#! /Bin/bashfor I in 'Find. -name "*. png "-o-name "*. jpg "'; do file = 'basename-s. jpg "$ I" | xargs basename-s. png | xargs basename-s @ 2x 'result = 'ack-I "$ file" 'if [-z "$ result"]; then echo "$ I" # if necessary, you can delete it directly: # rm "$ I" fidone

 
 

(2) Save the file name: deletePhoto. sh. Remember the saved path:/Users/linafu/deletePhoto.

(3) add execution permissions to the script file: Enter the following script on the terminal: chmod + x./deletePhoto

Now, the shell script is ready!

2. Execute the created script in xcode:

(1) In the xcode menu bar: file-> new-> target, osx-> other-> external build system, name it scriptTarget, in this way, a virtual target is created.

(2) in the target area of the project, select scriptTarget and enter/Users/linafu/deletePhoto In the build tool.

(3) add scriptTarget to build phasese-> target dependencies of the target project.

All right, in the future, the virtual target will be built before the build project, and the script will be run through the build target. Of course, we do not need to delete the image every time we compile it. Therefore, we can remove it from build phasese-> target dependencies after use.


Forget to say that before all the steps, install ack (ack is used for search) through the brew install ack command on the terminal ).

Haha, it is too inconvenient to add, so you cannot understand the link in the article. In addition, here is another method to delete images not used in ios, using the python script: Portal


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.