2012-03-26 21 views
2

在我的iOS应用程序中,我制作了一个表单,应该将数据提交给plist。我按照例子从这个链接除其他 -将文件添加到我的Plist中 - 我想我差不多有

How to write a data in plist?

现在我认为我所做的一切都是正确的,除了我得到一个错误,它关系到ARC - 说的Xcode - 所以我不知道如果示例我用过时了,或者我忘记了一些东西。为了说明 - 我有保存按钮与相应的 - (IBAction),它没有给出任何错误,所以我认为我在那里确定。我认为需要调整的位是将原始Data.plist复制到文档文件夹中,我认为我应该用这个文件夹来实现。

我粘贴了下面的错误发生的代码。任何帮助是巨大的,如果我可以通过发布更多的代码帮助,让我知道:-)

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view. 


NSString *destPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; 
destPath = [destPath stringByAppendingPathComponent:@"Data.plist"]; 

// If the file doesn't exist in the Documents Folder, copy it. 
NSFileManager *fileManager = [NSFileManager defaultManager]; 

if (![fileManager fileExistsAtPath:destPath]) { 
    NSString *sourcePath = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"]; 
    [fileManager copyItemAtPath:sourcePath toPath:destPath]; 
} 

// Load the Property List. 
savedReadingsDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:destPath]; 
} 

干杯杰夫

我只注意到我没有澄清什么是给我的错误:

这是该行

[fileManager copyItemAtPath:sourcePath toPath:destPath]; 

和错误是:

ARC Issue - No visible @interface for 'NSFileManager' declares the selector 'copyItemAtPath:toPath:'

回答

2

你已经使用了一个不存在的方法。你只需要改变它作为

[fileManager copyItemAtPath:sourcePath toPath:destPath error:nil]; 

不是传递nil为错误的,你也可以通过自定义NSError对象。参考NSFileManager class reference查看所有允许的方法

+0

似乎摆脱了错误谢谢 - 没有调试为什么我得到的NSDictionary问题 - 谢谢:-) – 2012-03-26 09:12:38

+0

没有问题的人!下个问题祝你好运! – tipycalFlow 2012-03-26 11:44:30

2

NSFileManager不包含该方法。

[fileManager copyItemAtPath: toPath:]; 

您应该使用下面的方法,

- (BOOL)copyItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath error:(NSError **)error NS_AVAILABLE(10_5, 2_0); 
+0

对不起,只是澄清 - 你的意思是交换另一个? – 2012-03-26 09:10:14

+0

@ jwk82。是的,我打算改变它。 – Vignesh 2012-03-26 09:20:12

相关问题