[题外介绍:其实本宅也是一名程序员,各种经验和问题总结也不少,只是工作比较忙,很少在网上发文。本着互联分享精神,但各种网站账号太多,不一一发了]
首先,这种问题一般出现在拷贝工程到另一台Mac上,用Xcode打开后,发现没法运行:Xcode竟然把它识别成Mac工程了,target在Xcode上的device选项竟然只有My Mac 64-bit”,能编译才怪呢!而拷回到原Mac上打开编译,运行正常,当前Mac打开其他工程也是正常的!
那么,是什么导致工程被Xcode识别出错呢?Xcode的bug我们这里就不说了,检查发现项目工程的.xcodeproj文件,在查看内容时(通常有三个:project.pbxproj, project.xcworkspace和xcuserdata文件夹)。xcuserdata里面有在不同Mac上打开后产生的缓存文件,这时候肯定有与之前Mac上编译相关的缓存文件,当前Xcode不能正常识别它,这也是问题所在!
解决方法,关闭工程,查看.xcodeproj文件里的内容,删除xcuserdata文件夹;重新打开项目工程,重新看到device列表里出现iPhone真机和模拟器了!command+shift+K清理一下,然后编译、运行。OK,应该没事了,Xcode在运行程序时会自动根据配置信息重新生成xcuserdata文件的。
project.xcworkspace说明:
is a directory of files describing the workspace or projects. Although some of the answers here indicate it is unnecessary and should be ignored for source control, I don't agree, but it's going to be highly dependent upon how you use your environment. Generally, the contents of the project.xcworkspace directory contains the contents.xcworkspace data file, which lists the projects that are included as top-level entities in your project。
xcuserdata说明:You can safely delete the xcuserdata directories. It basically contains personal settings like breakpoints, user interface layout, open files, automatic snapshots configuration and so on。
结论:
an xcuserdata directory, which contains each user's settings (should be ignored for source code controL), and xcshareddata, which is data shared by users who share a project, and should be under source control.
in environments where you don't share workspaces, or where you use simple workspaces, you can ignore these as well, however in environments where you put related projects in the same workspace and share that configuration, you may well want to keep these.