少了 Assets.xcassets 的我該怎麼辦

身為十年經驗的 Swift iOS App 開發魔法師,我們都知道 Asset 十分重要,App 顯示的圖片都在裡面(網路上下載和使用者拍照生成的圖片例外)。

比方以下 storyboard 的某個 image view,顯示著 Assets.xcassets 裡的圖片 book2。

但是,如果你不小心手殘,按到 Remove Reference 將 Assets.xcassets 刪除的話 ?

這時候就好像 App 裡寶貴的圖片都被虎克船長偷走,storyboard 的 image view 將顯示可怕的問號 !

此時,按 cmd + z 上一步是沒用的,因為刪除檔案的動作無法上一步,就好像分手說出口就無法挽回一樣。

不過好在 Assets.xcassets 還存在這個世界上,你只要從 Finder 進到專案的資料夾,找到 Assets.xcassets,將它拖曳到 Xcode 的 Project navigator 即可。

最後,還有一個動作要做,你要點選 Assets.xcassets,從右邊的 File inspector 頁面確認 Target Membership 下的 App 被勾選。如果沒勾選,到時候 Xcode 生成 App 時,可是會忘記將 Assets.xcassets 包進去的。

彼得潘的 Swift iOS App 開發問題解答集

彼得潘和學生們在開發 iOS App 路上曾經解決的問題集

彼得潘的 iOS App Neverland

Written by

彼得潘的 Swift 程式設計入門,App程式設計入門作者,彼得潘的iOS App程式設計入門,文組生的iOS App程式設計入門講師,http://apppeterpan.strikingly.com

彼得潘的 Swift iOS App 開發問題解答集

彼得潘和學生們在開發 iOS App 路上曾經解決的問題集

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade