Fix: unable to initiate PIF transfer session in Xcode

Fix: unable to initiate PIF transfer session in Xcode

Written by

in

Quick answer: Quit and reopen Xcode, then choose Product > Build or press Command-B before trying to run the app. If the error persists, quit Xcode again, remove the affected project’s Derived Data, and clear the repositories folder and repositories.lock file inside ~/Library/Caches/org.swift.swiftpm.

Why this happens

Xcode can stop before compiling your app with this build-service error:

Build service could not create build operation: unknown error while handling message: MsgHandlingError(message: "unable to initiate PIF transfer session (operation in progress?)")

PIF refers to the Project Interchange Format used in Xcode’s build infrastructure. This message means Xcode could not begin transferring the project information needed to create a build operation. It does not, by itself, identify a mistake in your Swift code.

The reported Xcode 14.3 cases point to temporary build-service state or cached project and Swift Package Manager data as useful troubleshooting targets. However, the message does not prove that a particular package or cache is corrupt. Start with a restart and a build-only attempt before deleting anything.

How to fix it

1. Quit Xcode, reopen it, and build without running

This is the first fix to try. The highest-rated answer includes this simpler approach as an update, and another highly rated answer also reports success from restarting Xcode.

  1. Save your changes.
  2. Quit Xcode completely with Command-Q. Closing the project window alone is not the same as quitting the application.
  3. Reopen your project or workspace.
  4. Let any visible package-resolution activity finish.
  5. Choose Product > Build, or press Command-B.
  6. If the build succeeds, try running the app normally.

The important detail is to try a regular build before using Run. A successful build verifies that Xcode can create the build operation without also asking it to launch your app.

If the same PIF error returns, proceed to the cache cleanup below. There is no need to change source files, signing settings, or the deployment target based on this message alone.

2. Remove the affected project’s Derived Data

Derived Data contains generated build products and other data Xcode can recreate. Removing it is different from deleting your project, but it does make the next build do more work.

Quit Xcode before performing the cleanup:

  1. Open Finder.
  2. Press Command-Shift-G to open Go to Folder.
  3. Enter this path:
~/Library/Developer/Xcode/DerivedData
  1. Find the folder associated with the affected project and move it to the Trash.
  2. Reopen Xcode and try Command-B again.

Project-specific Derived Data folders normally include the project name followed by a generated suffix. If you cannot confidently identify the right folder, do not guess at unrelated locations.

The original workaround removed the entire Derived Data directory. That is a broader option if targeted cleanup does not help, but it also removes generated data for other projects. Prefer the project-specific folder first to avoid unnecessary rebuilds elsewhere.

Deleting Derived Data alone did not resolve the original questioner’s case. If the error remains, the next step addresses the additional Swift Package Manager cache locations included in the reported solution.

3. Clear Swift Package Manager’s repository cache

The accepted workaround combined Derived Data cleanup with removal of two items in Swift Package Manager’s cache: repositories and repositories.lock.

With Xcode closed:

  1. Open Finder and press Command-Shift-G.
  2. Enter:
~/Library/Caches/org.swift.swiftpm
  1. Inside that location, look for:
repositories
repositories.lock
  1. Move those items to the Trash if they exist.
  2. Reopen your project or workspace in Xcode.
  3. Allow package resolution to finish, then press Command-B.

If Finder presents the cache location as a package rather than an ordinary folder, use Show Package Contents to inspect it. If the directory or either named item is absent, skip the missing item rather than creating it or deleting a similarly named file elsewhere.

These are cache items, not your package source declarations. Removing them can require Swift Package Manager to fetch repositories again, so make sure your network connection and any credentials needed for private dependencies are available.

Do not confuse repositories.lock with Package.resolved. The former is the cache file named in this workaround. The latter records resolved dependency versions for your project or workspace. Deleting Package.resolved is not part of this fix and can introduce dependency changes that make troubleshooting harder.

4. Check what happens after the rebuild

After cleanup, distinguish between the original build-service failure and a new error.

  • The build succeeds: Try running the app. No further cache cleanup is necessary.
  • Package resolution fails: Address the reported repository, authentication, or network problem before attempting another build.
  • A compiler error appears: Xcode has progressed beyond the initial PIF failure. Investigate that specific diagnostic instead.
  • The identical PIF error remains: Record the Xcode version, affected workspace, and whether another project builds successfully before making broader changes.

The source also includes an anecdotal workaround involving a build in Xcode 14.1 or 14.2 followed by a return to Xcode 14.3. Treat that as a fallback experiment, not a required fix: older Xcode versions may not support your project’s SDK or project settings.

If you already have a compatible older Xcode installation, save or commit your work before trying it, and review any project-file changes afterward. Installing an older toolchain solely for this error is a much larger intervention than restarting Xcode or clearing the named caches.

How to prevent it

There is no guaranteed prevention established by these reports. Keep recovery predictable instead:

  • Avoid deleting caches while Xcode is building or resolving packages; quit it first.
  • Keep dependency-version files under version control when appropriate for your project, so unintended resolution changes are visible.
  • Change one troubleshooting variable at a time, then retry Command-B.
  • Do not turn broad cache deletion into a routine build step. Use it when there is a specific failure to investigate.
  • Record which action actually restores the build, especially if the error returns.

FAQ

Do I need to change my Swift code to fix this error?

Not based on this message alone. It describes a failure to create the build operation, so start with Xcode state and cache recovery rather than editing application code.

Why did deleting Derived Data not fix the PIF transfer error?

Derived Data is only one part of Xcode’s generated state. The reported workaround also cleared Swift Package Manager’s repository cache, while other reports needed only a full Xcode restart and a build-only attempt.

Is it safe to delete the Swift Package Manager cache?

The named cache items can be recreated, but packages may need to download again. Quit Xcode first, delete only the specified cache items, and leave your source files and Package.resolved unchanged.

Sources & credits

Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.