i have a problem in the creation of my db file. I’m using this function:
- (void)createEditableCopyOfDatabaseIfNeeded {
// Testing for existence
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:DATABASE_NAME];
NSLog(@"%@", writableDBPath);
success = [fileManager fileExistsAtPath:writableDBPath];
if (success) {
NSLog(@"The file was here");
return;
}
// The writable database does not exist, so copy the default to
// the appropriate location.
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath]
stringByAppendingPathComponent:DATABASE_NAME];
success = [fileManager copyItemAtPath:defaultDBPath
toPath:writableDBPath
error:&error];
NSLog(@"New file created");
if(!success)
{
NSAssert1(0,@"Failed to create writable database file with Message : '%@'.",
[error localizedDescription]);
}
}
Executing this always generate the log “New file created”, but if i point my finder to the db path i find an empty folder: the file was not created!
What is the problem in your opinion?
(I have another app using the same function, and works well!)
UPDATE:
If i use the “go to folder” function of finder and paste in the defaultDBPath, it tells me that i don’t have the privileges required to access the folder
Ok i solved it… very stupid of me!
Simply i were setting the DATABASE_NAME to “villaggio.
db“, while my real db was named “villaggio.sqlite” !!!=D