问题描述
Xcode关闭并重新添加App Sandbox和Hardened Runtime后,运行程序时,Xcode会报错:
error: Entitlements file "SnapSlim.entitlements" was modified during the build, which is not supported. You can disable this error by setting 'CODE_SIGN_ALLOW_ENTITLEMENTS_MODIFICATION' to 'YES', however this may cause the built product's code signature or provisioning profile to contain incorrect entitlements.

错误信息表示:
Xcode 在编译过程中检测到 SnapSlim.entitlements 文件被修改了,而这是不被允许的行为。
问题原因在于,我们改动App Sandbox和Hardened Runtime时,会动态更改 .entitlements 文件。
Xcode 要求 .entitlements 是静态不变的文件,以确保代码签名(Code Signing)能准确绑定权限。
解决方案
清理构建缓存:

或者手动清理:
rm -rf ~/Library/Developer/Xcode/DerivedData/*
清理构建缓存后,重新构建并运行应用,问题得到解决。