Мой метод checkIfExistDatabase должен вернуть YES для второго запуска, но он возвращает NO.Это проблема.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[CoreDataWrapper sharedInstance] checkIfExistDatabase];
return YES;
}
-(void) checkIfExistDatabase
{
NSURL *url = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Mew.sqlite"];
BOOL isExists = [[NSFileManager defaultManager] fileExistsAtPath:[url absoluteString]];
if (!isExists)
{
[self populateDatabase];
}
}
-(void) populateDatabase
{
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Test" inManagedObjectContext:[self managedObjectContext]];
for (int i =0; i<2; i++)
{
Test *test = [[[Test alloc] initWithEntity:entity insertIntoManagedObjectContext:[self managedObjectContext]] autorelease];
test.text = @"Text";
test.index = [NSNumber numberWithInt:i];
}
[self saveContext];
}
ОБНОВЛЕНИЕ: я добавил метод applicationDocumentsDirectory
- (NSURL *)applicationDocumentsDirectory
{
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}
и вывод:
NSLog(@"absolute string: %@", [url absoluteString]);
absolute string: file://localhost/var/mobile/Applications/6EE4D791-B798-4A2E-83DD-BFA41ED86940/Documents/Mew.sqlite