目标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方法错了吗?
答案 0 :(得分:1)
使用错误指示器来理解错误:
NSError *error;
BOOL status = [[NSFileManager defaultManager] copyItemAtURL:source toURL:destination error:&error];
if (status == NO ) {
NSLog(@"errorL %@", error);
}