If you're using Cocoapods, make sure you're building dynamic frameworks by having use_frameworks! in your Podfile.
When I was building static libraries of my Cocoapods dependencies on Xcode 10.2.1 and Cocoapods 1.6.1, I couldn't debug the target because of this "could not attach" error. With use_frameworks!, the error was gone and I could debug again.
Details
In my Podfile, I was building a static framework, which is the default, with a mix of swift and objective-c based pods. I used the :modular_headers => true with one of the pods. My Podfile looked something like this:
swift_version = '5.0'
target 'TargetName' do
platform :ios, '12.2'
pod 'IGListKit', :modular_headers => true
pod 'PromiseKit/CorePromise', '~> 6.0'
end
The above Podfile couldn't be debugged with Xcode 10.2.1, always resulting in the "Could not attach to PID" modal.
But, when I added use_frameworks!, it worked! I was able to repro it with and without. Here is the Podfile that worked:
swift_version = '5.0'
use_frameworks!
target 'TargetName' do
platform :ios, '12.2'
pod 'IGListKit'
pod 'PromiseKit/CorePromise', '~> 6.0'
end