DerivedData Deletion - Useful Commands

Why delete DerivedData

The DerivedData folder is a directory used by Xcode to store intermediate build outputs, including compiled code, logs, and other temporary files. While it can be helpful in speeding up the build process, over time, the folder can accumulate a large amount of data, which can take up valuable disk space. Additionally, the contents of the DerivedData folder can sometimes become corrupted, leading to build errors and other issues. In such cases, deleting the DerivedData folder can help resolve these issues and free up disk space, allowing Xcode to recreate the necessary files the next time you build your project. Therefore, it may be necessary to delete the DerivedData folder periodically to ensure optimal performance and stability when working with Xcode.


alias goto-DerivedData="cd $DERIVED_DATA"

alias derivedData-Delete="XcodeDeleteDerivedData"
alias XcodeDeleteDerivedData="rm -rf $DERIVED_DATA"

This code is defining four aliases in a Bash shell environment that are related to the DerivedData folder used by Xcode.

The first line assigns the path of the DerivedData folder to the DERIVED_DATA variable. The ~ in the path is a shortcut for the user’s home directory.

The second line creates an alias named goto-DerivedData that changes the current working directory to the DerivedData folder. This alias saves the user from having to type the full path to the DerivedData folder every time they need to access it.

The third line creates an alias named derivedData-Delete that calls another alias named XcodeDeleteDerivedData.

The fourth line creates an alias named XcodeDeleteDerivedData that deletes the entire contents of the DerivedData folder using the rm -rf command. The -rf option stands for “recursive force” and tells the command to delete all files and subdirectories within the DerivedData folder, even if they are write-protected or hidden.

Overall, these aliases provide convenient shortcuts for navigating to and deleting the DerivedData folder used by Xcode, which can help free up disk space and resolve build errors.