2014-09-27 14 views
10

mam ten błąd za każdym razem, że mogę zainstalować aplikację na Simulator korzystając Xcode 6CoreData: error: -addPersistentStoreWithType: SQLite konfiguracja: (null)

2014-09-27 11:25:01.286 MyFace[2992:1780149] CoreData: error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///Users/douglasferreira/Library/Developer/CoreSimulator/Devices/DAC1BEDE-8673-471C-ADFD-923654C78719/data/Containers/Data/Application/D2213EE4-3807-44FF-9FD0-E7C6C1BD18A2/Library/MyFace.sqlite options:{ 
NSInferMappingModelAutomaticallyOption = 1; 
NSMigratePersistentStoresAutomaticallyOption = 1; 
} ... returned error Error Domain=NSCocoaErrorDomain Code=512 "The operation couldn’t be completed. (Cocoa error 512.)" UserInfo=0x7fe566317030 {reason=File appeared during sanity check; this seems suspicious} with userInfo dictionary { 
reason = "File appeared during sanity check; this seems suspicious"; 
} 

[2014-09-27 11:25:01:288] [ERROR] Problems to initialize persistent store coordinator: Error Domain=NSCocoaErrorDomain Code=512 "The operation couldn’t be completed. (Cocoa error 512.)" UserInfo=0x7fe566317030 {reason=File appeared during sanity check; this seems suspicious}, The operation couldn’t be completed. (Cocoa error 512.) 

ten sposób tworzę NSManagedObjectModel i NSPersistentStoreCoordinator

- (NSManagedObjectModel *)managedObjectModel 
{ 
    if (!_managedObjectModel) 
    { 
     // It is created from the application's model with the following name and extension 
     NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"MyFace" withExtension:@"momd"]; 
     _managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; 
    } 
    return _managedObjectModel; 
} 

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator 
{ 
    if (!_persistentStoreCoordinator) 
    { 
     // generic variable to hold any error occurred during context creation 
     NSError *error = nil; 

     NSDictionary *persistentOptions = @{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES}; 

     // Create the coordinator with the previous parameters 
     NSURL *storeURL = [[[NSFileManager defaultManager] URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask] lastObject]; 
     storeURL = [storeURL URLByAppendingPathComponent:@"MyFace.sqlite"]; 

     // try to initialize persistent store coordinator with options defined below 
     self.persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:self.managedObjectModel]; 
     [self.persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType 
                 configuration:nil 
                   URL:storeURL 
                  options:persistentOptions 
                   error:&error]; 

     if (error) 
     { 
      NSLog(@"[ERROR] Problems to initialize persistent store coordinator: %@, %@", error, [error localizedDescription]); 
     } 
    } 
    return _persistentStoreCoordinator; 
} 

Próbowałem każdego rodzaju flagi .. ale nie wiem jak to rozwiązać.

Dzięki!

+0

Zastanawiam się, czy jest to problem ze ścieżką. Czy otrzymasz to samo, jeśli użyjesz 'NSDocumentDirectory' zamiast' NSLibraryDirectory'? –

+0

Mam inny błąd. Myślę, że jest gorzej. 'Error Domain = NSCocoaErrorDomain Code = 512" Operacja nie mogła zostać zakończona. (Błąd kakao 512.) "UserInfo = 0x7fbec9c36e70 {reason = Nie powiodło się utworzenie pliku; code = 2}, Operacja nie mogła zostać zakończona. (Błąd kakao 512.) ' –

Odpowiedz

11

Znalazłem rozwiązanie mojego problemu. Mam dwa wątki dostępu do NSPersistentStoreCoordinator, podczas gdy jeszcze nie został utworzony. Więc dodałem @synchronize na leniwym init i ustawiłem w kolejce żądania.

0

Douglas ma rację. W przypadku urządzeń typu iOS takich jak ja, sformułowanie będzie następujące:

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator 
{ 
    @synchronized(self) { 

     if (!_persistentStoreCoordinator) 
     { 
      // generic variable to hold any error occurred during context creation 
      NSError *error = nil; 

      NSDictionary *persistentOptions = @{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES}; 

      // Create the coordinator with the previous parameters 
      NSURL *storeURL = [[[NSFileManager defaultManager] URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask] lastObject]; 
      storeURL = [storeURL URLByAppendingPathComponent:@"MyFace.sqlite"]; 

      // try to initialize persistent store coordinator with options defined below 
      self.persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:self.managedObjectModel]; 
      [self.persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType 
                  configuration:nil 
                    URL:storeURL 
                   options:persistentOptions 
                    error:&error]; 

      if (error) 
      { 
       NSLog(@"[ERROR] Problems to initialize persistent store coordinator: %@, %@", error, [error localizedDescription]); 
      } 
     } 

    } 
    return _persistentStoreCoordinator; 
} 
Powiązane problemy