这段代码的结果是,网址为空如何从包含空格的字符串创建NSURL?
NSString* home = [NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Application Support/"];
NSURL *url = [NSURL URLWithString:home];
,所以是这样的:
NSString* home = [NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Application Support/"];
home = [home stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:home];
经由如果创建URLForDirectory的URL:被送入NSFileManger:enumeratorAtPath:(第一后其转换为使用absoluteString字符串),然后返回NSDirectoryEnumerator是空的。我最初使用URLForDirectory与enumeratorAtURL结合使用:但无法使用我所做的操作切换到enumeratorAtPath,但这似乎不适用于URLForDirectory。请参阅http://stackoverflow.com/questions/11546974/nsfilemanagerenumeratoraturl-returns-a-different-form-of-url-to-nsfilemanager – Gruntcakes 2012-07-18 20:55:03
@ ChrisP.Bacon同样,这是使用正确API的问题。如果你有一个文件的URL,你不应该通过调用'-absoluteString'将它转换为路径,你应该*通过调用'-path'方法将它转换为路径。 – 2012-07-18 21:15:45