NSBundle 獲取檔案路徑為空

2021-07-30 09:24:10 字數 395 閱讀 8265

nsstring

*filepath = [[

nsbundle

mainbundle

] pathforresource

:@"test.m2"

oftype

:nil];

執行後filepath是空的,但是已經把這個檔案加到xcode中了,

上網查了下發現由於當時是直接拖進去的,沒有新增到資源檔案路徑,

需要採用add file to 方式新增檔案。

但是這樣有時也會因為xcode的原因新增不到資源檔案中。

在專案設定中

build phases > copy bundle resources

中可以檢視已經新增進去的資源檔案,如果裡面沒有,那就需要在這裡手動新增了。

NSBundle 獲取檔案路徑

之前在初始化乙個類的時候 testviewcontroller viewcontroller testviewcontroller alloc initwithnibname testviewcontroller bundle nsbundle mainbundle 不是很明白 nsbundle m...

NSBundle方法獲取不到資源路徑

ios問題筆記 nsbundle mainbundle pathforresource oftype 方法獲取不到資源路徑 ios開發在一次使用資料庫檔案時 nsstring filepath nsbundlemainbundle pathforresource city oftype sqlite...

NSBundle路徑問題

先上圖 上面是乙個程式檔案的主要路徑圖,我們平時獲取預設路徑或者儲存檔案路徑的兩種方式 nsstring bundlepath nsbundle mainbundle resourcepath nsstring documentpath nssearchpathfordirectoriesindom...