Xcode 9: Could not attach to pid

I've been facing an issue (frequently) with the recent major release of the iOS application development tool - Xcode 9-beta.

It's showing me the following error frequently while running/debugging app in Simulator (iOS 11).

Could not attach to pid : “2370”
Ensure <project title> is not already running, and <system username> has permission to debug it.

Here is a snapshot for the same issue:

error message - Could not attach to pid

What would be permanent solution of this issue, as it's disturbing frequently?


Solution 1:

If issue is on OS Mojave and you are trying, like me to run tests on older Xcode version (lower than 10.0), make sure that in your scheme, when you select Test, Debug executable is disabled

enter image description here

You won't be able to debug tests from this point

Solution 2:

Still not a permanent solution, but I had to quit and restart Xcode as the other solutions did not work for me.

Solution 3:

This worked for me:

Edit Scheme -> Info -> Executable -> Ask on launch

Credits to @nastya-gorban's answer here

Update

After spending a considerable time with examples on Apple bug report, they basically disregarded the issue as using manual certificates is not "expected".

Long story short, if you don't have a business account and hence multiple developers on the same account, you should be fine with using the automatic signing and should not see the issue.

If you do have a business account with multiple users (which I found it breaks automatic signing), this is their suggestion:

We suggest that you use automatic signing for your debug builds and manual signing for your distribution builds.

Solution 4:

Killing my simulator and then running it again from Xcode.

Solution 5:

I had this issue too. There seems to be an issue with having two Xcode version installed at the same time. (9.4.1 and 10.0 Beta)

It works with the beta, but not with the stable version. Everything is set to the tools of the Xcode 9.4.1 stable version. I can only run my unit tests with the beta.

After removing the beta, it worked with the stable version.