#imageLiteral(resourceName: “xxx”)

從 Xcode 8 開始,我們在程式裡可以很方便地輸入 Assets 裡的圖片名稱,產生 UIImage ,比方圖片名稱是 peter1,只要輸入 peter1,即可產生它的 UIImage 物件。

在 Xcode 的程式編輯畫面裡,剛剛輸入 peter1 生成的 UIImage 物件會變成美美的圖片,但是如果你將程式碼貼到一般的文字編輯器,將會變成 #imageLiteral 的格式,比方剛剛的例子,程式碼將變成

其實這段文字才是程式碼的真實模樣,顯示成美美圖片的樣子,只是 Xcode 用它的特異功能幫我們美化。

彼得潘的 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