I am trying to set up my application so that on first launch, a series of files located in the \"Populator\" folder in the main bundle are copied into the documents director
NSError *error;
You are declaring a local variable without initializing it. Therefore, it will be filled with garbage.
[[NSFileManager defaultManager] copyItemAtPath:sourcePath
toPath:folderPath
error:&error];
If no error occurs on this line, the garbage status of error
would still remain.
NSLog(@"Error description-%@ \n", [error localizedDescription]);
Now you send a message to some random, uninitialized location. This is the source of the crash.
To avoid this, initialize error
to nil
.
NSError* error = nil;
// ^^^^^
Or print the error only when -copyItemAtPath:…
returns NO (in which the error
is correctly populated).
if (![[NSFileManager defaultManager] copyItemAtPath:sourcePath ...]) {
NSLog(...);
}