The following are a collection of useful tips and tricks I've developed over the past year to help keep things neat and tidy in my development environment.
Free up space taken by Xcode
The problem: Xcode is a huge space hog, not only in the size of the app, but with all of the detritus which is left about from old archives, simulators, and derived data. This often results in my work computer displaying low space warnings.
- Run a disk sweeper to find where the most space is being taken and then delete files from:
- Derived data:
- Device logs:
~/Library/Developer/Xcode/iOS Device Logs
- Old simulators:
- Really old simulators:
~/Library/Application Support/iPhone Simulator
- Old documentation:
- Remove old simulators and devices from
~/Library/Developer/CoreSimulator/Deviceswith the command:
xcrun simctl delete unavailable
- Reboot your computer to free up memory
Clean up old local git branches
The problem: Without regular maintenance, your local git repository will become a cluttered mess of old branches. Before cleaning your local git branches, your repository might look like this:
$ git branch --merged Bugfix/FOOBAR-1000 Bugfix/FOOBAR-1007 Bugfix/FOOBAR-1015 Bugfix/FOOBAR-1026 Bugfix/FOOBAR-1057 Bugfix/FOOBAR-1058 Bugfix/FOOBAR-1060 Bugfix/FOOBAR-1061 Bugfix/FOOBAR-1062 Bugfix/FOOBAR-1099 Bugfix/FOOBAR-1106 Bugfix/FOOBAR-1132 Bugfix/FOOBAR-1139 Bugfix/FOOBAR-1141 Bugfix/FOOBAR-1151 Bugfix/FOOBAR-1155 Bugfix/FOOBAR-1157 Bugfix/FOOBAR-1168 Bugfix/FOOBAR-1172 Bugfix/FOOBAR-1181 Bugfix/FOOBAR-1206 Bugfix/FOOBAR-1242 Bugfix/FOOBAR-1250 Bugfix/FOOBAR-953 Bugfix/FOOBAR-997 Bugfix/FOOBAR-998 * develop feature/FOOBAR-1200 feature/FOOBAR-142 feature/FOOBAR-215 feature/FOOBAR-221 feature/FOOBAR-241 feature/FOOBAR-242 feature/FOOBAR-261 feature/FOOBAR-277 feature/FOOBAR-287 feature/FOOBAR-778 feature/FOOBAR-798 feature/FOOBAR-896 feature/FOOBAR-90 feature/FOOBAR-90-merge feature/FOOBAR-906 feature/FOOBAR-960 feature/stores/search master
Using a git/grep/xargs concoction, you can quickly clean this up. Delete all local merged branches, except for the branches named
git branch --merged | grep -v '\*\|master\|develop' | xargs -n 1 git branch -d
This will result in local branches being deleted, with output similar to this:
Deleted branch Bugfix/FOOBAR-1000 (was ab382ed). Deleted branch Bugfix/FOOBAR-1007 (was 493b17b). Deleted branch Bugfix/FOOBAR-1015 (was e7e1f6a). Deleted branch Bugfix/FOOBAR-1026 (was 19b6d62). Deleted branch Bugfix/FOOBAR-1057 (was 8f06d42). Deleted branch Bugfix/FOOBAR-1058 (was e285fde). Deleted branch Bugfix/FOOBAR-1060 (was 96318b5). Deleted branch Bugfix/FOOBAR-1061 (was a84bcac). Deleted branch Bugfix/FOOBAR-1062 (was 2b7310c). Deleted branch Bugfix/FOOBAR-1099 (was 8260dd0). Deleted branch Bugfix/FOOBAR-1106 (was cf401f2). Deleted branch Bugfix/FOOBAR-1132 (was 4af883c). Deleted branch Bugfix/FOOBAR-1139 (was 3f89c9b). Deleted branch Bugfix/FOOBAR-1141 (was 13763d0). Deleted branch Bugfix/FOOBAR-1151 (was 6ca43c4). Deleted branch Bugfix/FOOBAR-1155 (was b020c21). Deleted branch Bugfix/FOOBAR-1157 (was 903dee7). Deleted branch Bugfix/FOOBAR-1168 (was abb20b6). . . .
Perform one more check to ensure that your local repository has been cleaned up:
$ git branch --merged * develop feature/FOOBAR-242 master
synx — Organize an Xcode project's file system
The problem: The file system structure of your project does not match up to the project's Xcode structure. If not properly handled early on in a project's life cycle, the organization between the project and it's matching file system will quickly become out of sync and result in a massive dump of unorganized files.
The idea to write a script seemed like a good weekend project, but fortunately this problem has already been solved. Enter
synx, a command-line tool that reorganizes your Xcode project folder to match your Xcode groups.
sudo gem install synx
...and viola!...er...ah....Voilá! No more unorganized file system structure.
Taking a simulator screenshot from the command line
The problem: As of Xcode 8, trying to take a screenshot of the iOS simulator using the keyboard shortcut
⌘-S will result in the simulator crashing. This issue occurs only with OS X El Capitan and Xcode 8, but not with macOS Sierra and Xcode 8.
From the command line, run:
xcrun simctl io booted screenshot
I created a small shell script named
tss.sh (short for Take Simulator Screenshot) which switches to the Desktop, takes the screenshot of the running simulator, saves the picture to the Desktop, then switches back to the original directory. I then created an alias so I only need to type
tss from the Terminal to take a screenshot.
To make this even easier, create an Automator Workflow service to run the shell script and then attach a keyboard shortcut to it. This method circumvents event needing to go to the command line to call the script. Press ⇧-⌘-5 and a screenshot is taken of the simulator.
- Google Slides for this presentation
- Xcode users can free up space on your Mac
- Xcode 6 – Reset Simulators from the Command Line
- How To Recover Disk Space From Xcode
- Xcode - free to clear devices folder?
- Git Clean: Delete Already-Merged Branches
- Git housekeeping tutorial: clean-up outdated branches in local and remote repositories
- synx GitHub Page
- Xcode 8.2 simulator crash when save screen shot
- tss.sh Gist