{"id":7496,"date":"2014-06-19T05:36:07","date_gmt":"2014-06-19T05:36:07","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/06\/19\/core-data-persistent-store-can-not-be-created-on-ios-5-1-collection-of-common-programming-errors\/"},"modified":"2014-06-19T05:36:07","modified_gmt":"2014-06-19T05:36:07","slug":"core-data-persistent-store-can-not-be-created-on-ios-5-1-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/06\/19\/core-data-persistent-store-can-not-be-created-on-ios-5-1-collection-of-common-programming-errors\/","title":{"rendered":"Core Data &#8211; persistent store can not be created on iOS 5.1-Collection of common programming errors"},"content":{"rendered":"<p>I get an error when I want to create a persistent store. When I build for iOS 5.0 there is no error and core data works successfully.<\/p>\n<p>Here&#8217;s the code for create the persistent store:<\/p>\n<pre><code>+ (NSManagedObjectContext *)getContext {\n\n    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],NSMigratePersistentStoresAutomaticallyOption,\n                             [NSNumber numberWithBool:YES],\n                             NSInferMappingModelAutomaticallyOption, nil];\n\n\n    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);\n    NSString *basePath = ([paths count] &gt; 0) ? [paths objectAtIndex:0] : nil;\n    NSURL *storeUrl = [NSURL fileURLWithPath:[basePath stringByAppendingFormat:@\"Database.sqlite\"]];\n    NSPersistentStoreCoordinator *persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[NSManagedObjectModel mergedModelFromBundles:nil]];\n    NSError *error = nil;\n\n    if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&amp;error]) {\n        NSLog(@\"error loading persistent store..\");\n        [[NSFileManager defaultManager] removeItemAtPath:storeUrl.path error:nil];\n        if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&amp;error]) {\n            NSLog(@\"Unresolved error %@, %@\", error, [error userInfo]);\n            \/\/abort();\n        }\n    }\n\n\n    NSManagedObjectContext *context = [[NSManagedObjectContext alloc] init];\n    [context setPersistentStoreCoordinator:persistentStoreCoordinator];\n\n    return context;\n\n\n}\n<\/code><\/pre>\n<p>The error log:<\/p>\n<pre><code>error loading persistent store..\n2012-07-15 13:16:31.440 Partyfinder[8213:707] Unresolved error Error Domain=NSCocoaErrorDomain Code=512 \"The operation couldn,\u00c4\u00f4t be completed. (Cocoa error 512.)\" UserInfo=0xde88ca0 {reason=Failed to create file; code = 1}, {\n    reason = \"Failed to create file; code = 1\";\n}\n2012-07-15 13:16:31.455 Partyfinder[8213:707] error loading persistent store..\n2012-07-15 13:16:31.458 Partyfinder[8213:707] Unresolved error Error Domain=NSCocoaErrorDomain Code=512 \"The operation couldn,\u00c4\u00f4t be completed. (Cocoa error 512.)\" UserInfo=0xdeb5360 {reason=Failed to create file; code = 1}, {\n    reason = \"Failed to create file; code = 1\";\n}\n2012-07-15 13:16:31.467 Partyfinder[8213:707] error loading persistent store..\n2012-07-15 13:16:31.470 Partyfinder[8213:707] Unresolved error Error Domain=NSCocoaErrorDomain Code=512 \"The operation couldn,\u00c4\u00f4t be completed. (Cocoa error 512.)\" UserInfo=0xdeb6680 {reason=Failed to create file; code = 1}, {\n    reason = \"Failed to create file; code = 1\";\n}\n2012-07-15 13:16:31.483 Partyfinder[8213:707] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'This NSPersistentStoreCoordinator has no persistent stores.  It cannot perform a save operation.'\n*** First throw call stack:\n(0x358fa88f 0x37ca1259 0x36230fe7 0x36299287 0x593e5 0x45917 0x5bfc3 0x5c487 0x5bfc3 0x5bf6b 0x45285 0x5bfc3 0x5a883 0x5e26b 0x358ca433 0x3588f533 0x3588f77b 0x358cead3 0x358ce29f 0x358cd045 0x358504a5 0x3585036d 0x374ec439 0x3335ccd5 0x42119 0x420c4)\nterminate called throwing an exception\n<\/code><\/pre>\n<p>Anyone knows how to resolve the error?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I get an error when I want to create a persistent store. When I build for iOS 5.0 there is no error and core data works successfully. Here&#8217;s the code for create the persistent store: + (NSManagedObjectContext *)getContext { NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7496","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7496","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7496"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7496\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7496"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}