這段代碼的結果是,網址爲空如何從包含空格的字符串創建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