Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 可可粉_Objective C_Cocoa_Nsfilemanager - Fatal编程技术网

Objective c 可可粉

Objective c 可可粉,objective-c,cocoa,nsfilemanager,Objective C,Cocoa,Nsfilemanager,我正在尝试制作一个带有用户界面的非常简单的rsync程序。我所需要的只是能够拖放两个文件路径,以便一个文件路径复制到另一个文件路径。现在,我只是想把桌面上的一个文件复制到桌面上的一个文件夹,但这根本不起作用。我正在使用标题为“源”和“目标”的文本字段删除我拖到其中的文件路径。我有以下代码: #import "AppController.h" @implementation AppController @synthesize source = _source, destination = _d

我正在尝试制作一个带有用户界面的非常简单的rsync程序。我所需要的只是能够拖放两个文件路径,以便一个文件路径复制到另一个文件路径。现在,我只是想把桌面上的一个文件复制到桌面上的一个文件夹,但这根本不起作用。我正在使用标题为“源”和“目标”的文本字段删除我拖到其中的文件路径。我有以下代码:

#import "AppController.h"

@implementation AppController

@synthesize source = _source, destination = _destination;

-(IBAction)sync:(id)sender
{
 NSFileManager *manager = [[NSFileManager alloc] init];
    //NSURL *source = [NSURL fileURLWithPath:@"/Users/crashprophet/Desktop/Time Out Tot Schedule.doc"];
  //  NSURL *destination = [NSURL fileURLWithPath:@"/Users/crashprophet/Desktop/untitled f     older 2"];
NSURL *source = [NSURL URLWithString:self.source.stringValue];
NSURL *destination = [NSURL URLWithString:self.destination.stringValue];


[manager copyItemAtURL:source toURL:destination error:nil];
NSLog(@"The source path is %@ and the destation path is %@",source, destination);
NSLog(@"Got here!");
}

@end

有什么想法吗?

如果字符串与注释中的字符串相似,则需要使用fileURLWithPath:。此外,目标路径不能只是一个文件夹,它的末尾需要一个文件名——您可以使用与原始路径相同的文件名,也可以给它一个新的文件名。从您正在使用的复制方法上的文档:

“dstURL
放置srcURL副本的URL。此参数中的URL不能是文件引用URL,并且必须在其新位置包含文件名。此参数不能为零。“

如果字符串与注释中的字符串相似,则需要使用fileURLWithPath:。此外,目标路径不能只是一个文件夹,它的末尾需要一个文件名——您可以使用与原始路径相同的文件名,也可以给它一个新的文件名。从您正在使用的复制方法上的文档:

“dstURL
放置srcURL副本的URL。此参数中的URL不能是文件引用URL,并且必须在其新位置包含文件名。此参数不能为零。“

NSLog您的
self.source.stringValue
self.destination.stringValue
,以确保它们正确无误。另外,创建一个错误对象并将其放入
CopyItemAttribute:toURL:error:
,然后检查它返回的内容。并决定是要
fileURLWithPath:
(在注释掉的代码中)还是
URLWithString:
(在真实代码中)。如果文本字段包含路径,则需要
fileURLWithPath:
。记录
self.source.stringValue
self.destination.stringValue
以确保它们正确无误。另外,创建一个错误对象并将其放入
CopyItemAttribute:toURL:error:
,然后检查它返回的内容。并决定是要
fileURLWithPath:
(在注释掉的代码中)还是
URLWithString:
(在真实代码中)。如果文本字段包含路径,则需要
fileURLWithPath: