2015-02-17 81 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