有時候想取工程中的文件路徑,比如圖片,用NSBundle的 pathForResource: ofType: 返回卻是nil
屏幕快照 2017-09-25 18.32.46.png
[[NSBundle mainBundle] pathForResource:@"img_1" ofType:@"jpg"]; 返回的結果為nil。
這是因為 在添加這些圖片的時候,這些文件沒有添加到mainBundle中,需要在項目設置:targets -> build phases -> copy bundle resources 下面添加自己的數據就可以了。
2b7c90cb-0e1e-4f50-a6a9-a1ddbc047685.png