初學者在目標C在這裏,我有這樣的代碼:目標C - 如何將文件從一個位置移動到另一個位置?
//Path of management log file
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *urlPath= [documentsDirectory stringByAppendingPathComponent:@"Logs/log.txt"];
NSURL *source = [NSURL fileURLWithPath:urlPath];
//Destination
NSURL * destination = [self.pathControl URL];
//Move file from source to that destination directory.
[[NSFileManager defaultManager] copyItemAtURL:source toURL:destination error:nil];
的問題是,它沒有做任何事情。它可以編譯,但沒有任何反應。我使用copyItemAtURL方法錯了嗎?
什麼pathControl的內容是什麼? – 2015-02-09 23:26:50
盧克,使用強制錯誤參數!真的,提供錯誤參數並添加一個返回狀態變量,然後在狀態爲「NO」時記錄錯誤變量。 – zaph 2015-02-09 23:41:37
@Zaph,不僅僅是一個命名約定,documentsDirectory只是一個變量名。它指向路徑/ User/admin/Library/Logs目錄。之後我將不得不更改名稱。 – deusmaximus 2015-02-09 23:41:37