Skip to content

Xcode Integration

Before setting up Xcode integration, first get Periphery working in a terminal, as you will be using the same command via Xcode. Your project may require passing the -destination argument to xcodebuild. This can be done by supplying it as an additional argument, e.g. periphery scan ... -- -destination "generic/platform=iOS Simulator".

Select your project in the Project Navigator and click the + button at the bottom left of the Targets section. Select Other and choose Aggregate. Hit Next.

The target template chooser with the Other category selected and the Aggregate template highlighted

Choose a name for the new target, e.g., “Periphery” or “Unused Code”.

The target options sheet with “Periphery” entered as the Product Name

In the Build Phases section, click the + button to add a new Run Script phase.

The Build Phases tab of the Periphery target with New Run Script Phase selected in the + menu

Copy and paste your Periphery command into the script input.

The Run Script phase containing a periphery scan command

You must disable User Script Sandboxing for the Run Script phase. Periphery requires access to your project’s index store and source files, which are blocked by Xcode’s default sandbox. To disable sandboxing, set the ENABLE_USER_SCRIPT_SANDBOXING option to No in the Build Settings for the Periphery aggregate target.

The Build Settings tab with ENABLE_USER_SCRIPT_SANDBOXING set to No for the Periphery target

You’re ready to roll. You should now see the new scheme in the dropdown. Select it and hit run.

The scheme dropdown in the Xcode toolbar with the Periphery scheme selected