自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

NSBundle pathForResource取不到值如何解決?

移動(dòng)開發(fā) iOS
在iOS項(xiàng)目開發(fā)過程中,總會(huì)遇到或多或少的問題,比如說,在使用NSBundle pathForResource取不到值,著實(shí)讓人糾結(jié),下面將奉上超級解決方案。

代碼如下:

  1. NSString *path = [[NSBundle mainBundle] pathForResource:@"sortednames" ofType:@"plist"]; 
  2.       NSLog(@"path = %@", path); 
  3.       NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path]; 

但是運(yùn)行出來,path一直是null

 

師父找了好久,終于找到答案了

http://stackoverflow.com/questions/3949368/nsbundle-pathforresource-is-null

記錄一下:

command-line tool是沒有bundle的,所以用NSBundle的時(shí)候一直是null, 如果要使用bundle獲取資源,那么需要添加application的target。

按照上述改法,添加了一個(gè)target之后,還有問題,依舊找不到文件

然后師父做了以下操作:

A745B63C-0CFD-4A6E-AC33-96F9FC63B6A6.png

在這里添加了文件之后,然后再運(yùn)行,文件就能取到了。

之后又嘗試了在command-line tool中也按照上述方法,添加文件

首先,默認(rèn)是沒有bundle選項(xiàng)的

F.png

其次,就算手動(dòng)添加了build phrase,再添加文件,運(yùn)行出來,還是取不到path

2.png

所以, 如果要使用bundle獲取項(xiàng)目中的資源, 必須要使用application

責(zé)任編輯:張葉青 來源: eoe Android開發(fā)者社區(qū)
相關(guān)推薦

2011-05-06 16:28:44

共享打印機(jī)

2021-03-08 08:16:42

MySQL分離架構(gòu)

2020-10-17 09:14:53

iPhone

2021-06-29 14:38:30

客戶期望值品牌挑戰(zhàn)CIO

2012-09-05 11:09:15

SELinux操作系統(tǒng)

2023-05-30 18:13:59

Git代碼

2010-04-29 17:46:31

Oracle死鎖

2023-10-11 12:35:29

Maven

2010-07-21 09:33:09

VMware View

2013-05-21 10:49:59

Windows硬件沖突

2017-07-20 07:30:16

大數(shù)據(jù)數(shù)據(jù)互聯(lián)網(wǎng)

2024-10-29 16:41:24

SpringBoot跨域Java

2015-07-01 09:47:38

2012-10-29 14:51:34

vSphere存儲(chǔ)虛擬化

2024-11-21 16:47:55

2013-02-26 17:31:50

思科路由協(xié)議路由器設(shè)置

2011-08-10 16:58:35

windowsXP黑屏

2013-03-11 10:17:13

路由協(xié)議路由器設(shè)置網(wǎng)絡(luò)連接設(shè)置

2020-06-01 20:27:26

Windows 10Windows電腦藍(lán)屏

2017-10-17 09:21:06

點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號