解決iOS工程被Xcode識別成Mac工程的問題

[題外介紹:其實本宅也是一名程序員,各種經驗和問題總結也不少,只是工作比較忙,很少在網上發文。本著互聯分享精神,但各種網站賬號太多,不一一發了]

首先,這種問題一般出現在拷貝工程到另一臺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文件的。

說明:英文好的話,你可以了解一下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.

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容