2015-02-17 113 views
0

我無法用CHCSVParser解析csv文件。我的csv文件不能「滿足流」,我認爲問題在於該文件的URL不好。我得到這樣的網址:URLWithString刪除NSString路徑的一部分

NSString *path = [[NSBundle mainBundle] pathForResource:@"file" ofType:@"csv"]]; 
NSURL *url = [NSURL URLWithString:path]; 

當我登錄path我得到這個字符串:

/Users/wilhelmmichaelsen/Library/Developer/CoreSimulator/Devices/11F0BE77-9179-4A7B-B03E-1143957A8D02/data/Containers/Bundle/Application/7FE0AD10-DE7A-4C6D-9EED-4A95F9C197AE/Climate.app/file.csv 

當我登錄url我得到這個字符串:

/Users/wilhelmmichaelsen/Library/Developer/CoreSimulator/Devices/11F0BE77-9179-4A7B-B03E-1143957A8D02/data/Containers/Bu ... le.csv 

這似乎是路徑字符串正在縮短(...)。這有點奇怪,我該如何解決?

+1

如果你想有一個網址,不要使用'pathForResource:ofType:'。使用'URLForResource:withExtension:'。 – rmaddy 2015-02-17 23:28:14

回答

0

您應該使用fileURLWithPath從路徑創建URL。

+0

啊可愛,謝謝! – 2015-02-17 22:10:04

0

您已使用URLWithString方法,並且此方法預計URLString僅包含允許在正確形成的URL中允許使用的字符。所有其他角色必須正確逃脫百分比。任何轉義百分比的字符都使用UTF-8編碼進行解釋。

要創建文件系統路徑的NSURL對象,請改爲使用fileURLWithPath:isDirectory:

Here is the referece of the Apple Developers Library Documentation for NSURL Class