Skip to content

Troubleshooting

It’s possible for the index store to become corrupt or out of sync with the source file. This can happen, for example, if you forcefully terminate (^C) a scan. To rectify this, you can pass the --clean-build flag to the scan command to force removal of existing build artifacts.

Code referenced within a preprocessor macro conditional branch is unused

Section titled “Code referenced within a preprocessor macro conditional branch is unused”

When Periphery builds your project, it uses the default build configuration, which is typically ‘debug’. If you use preprocessor macros to conditionally compile code, Periphery will only have visibility into the branches that are compiled. In the example below, releaseName will be reported as unused as it is only referenced within the non-debug branch of the macro.

struct BuildInfo {
let debugName = "debug"
let releaseName = "release" // 'releaseName' is unused
var name: String {
#if DEBUG
debugName
#else
releaseName
#endif
}
}

You have a few options to work around this:

  • Use Comment Commands to explicitly ignore releaseName.
  • Filter the results to remove known instances.
  • Run Periphery once for each build configuration and merge the results. You can pass arguments to the underlying build by specifying them after --, e.g., periphery scan ... -- -configuration release.

Periphery uses swift build to compile a Swift package, which will fail if the Swift package is platform-specific (e.g., to iOS).

As a workaround, you can manually build the Swift package with xcodebuild and then use the --skip-build and --index-store-path options to target the index store previously produced by xcodebuild.

Terminal window
# 1. Use xcodebuild
xcodebuild -scheme MyScheme -destination 'platform=iOS Simulator,OS=16.2,name=iPhone 14' -derivedDataPath '../dd' clean build
# 2. Use produced index store for scanning
periphery scan --skip-build --index-store-path '../dd/Index.noindex/DataStore/'