2

In my iOS application I have made a form that should submit data into a plist. I have followed examples from this link amongst other -

How to write a data in plist?

Now the I think I have done everything right except I am getting one error and it is related to ARC - says Xcode - so I am not sure if the example I used is outdated or if I have just forgotten something.

To clarify - I have the save button with the appropriate -(IBAction) and it is giving no errors so i think I am ok there. the bit that needs tweaking I think is copying the original Data.plist into the document folder which I think I am suppose to achieve with this.

I have pasted the code where the error occurs below. Any help is great and if I can help by posting more code, let me know:-)

- (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];
}

Cheers Jeff

I just noticed I didn't clarify what is giving me the error:

it's this line

[fileManager copyItemAtPath:sourcePath toPath:destPath];

and the error is:

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

Community
  • 1
  • 1
jwknz
  • 6,598
  • 16
  • 72
  • 115

2 Answers2

2

NSFileManager doesn contain the method.

[fileManager copyItemAtPath: toPath:];

You should use the following method,

- (BOOL)copyItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath error:(NSError **)error NS_AVAILABLE(10_5, 2_0);
Vignesh
  • 10,205
  • 2
  • 35
  • 73
2

You've used a method that doesn't exist. You just need to change it as

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

Instead of passing nil as error, you can also pass your custom NSError object. Refer to the NSFileManager class reference to see all allowed methods

tipycalFlow
  • 7,594
  • 4
  • 34
  • 45
  • That seemed to get rid of the error thank you - no onto debugging on why I am getting the NSDictionary issue - thank you:-) – jwknz Mar 26 '12 at 09:12