title: CoreData "Error validating url for store"
body: <p>I'm having a problem in my application, CoreData works as it should in he simulator - but not on the device.</p>
  
  <p>I receive an </p>
  
  <pre><code>2010-09-30 12:45:07.500 CoreDataTutorial_iOS[130:307] Unresolved error Error Domain=NSCocoaErrorDomain Code=513 "The operation couldn’t be completed. (Cocoa error 513.)" UserInfo=0x1412a0 {NSUnderlyingException=Error validating url for store}, {
      NSUnderlyingException = "Error validating url for store";
  </code></pre>
  
  <p>I'm calling for the PersistentStoreCoordinator in this function (which throws the error above):</p>
  
  <pre><code>-(NSPersistentStoreCoordinator*)persistentStoreCoordinator
  {
      if(persistentStoreCoordinator_ != nil) 
          return persistentStoreCoordinator_;
  
      NSURL *aStoreURL = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingFormat:@"corebase.sqlite"]];
      NSError *anError = nil;
  
      persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
      if(![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:aStoreURL options:nil error:&amp;anError])
      {
          NSLog(@"Unresolved error %@, %@", anError, [anError userInfo]);
          abort();
      }
  
      return persistentStoreCoordinator;
  }
  </code></pre>
  
  <p>I'm setting a break point, on "objc_exception_throw", to see what the aStoreURL is, and it is:
  file://localhost/var/mobile/Applications/BE9A2982-BDC3-405D-A201-FB78E9E0790B/Documentscorebase.sqlite</p>
  
  <p>I notice it's not itself adding the final "/" after "/Documents". 
  When I created the URL this way</p>
  
  <pre><code>NSURL *aStoreURL = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingFormat:@"/corebase.sqlite"]];
  </code></pre>
  
  <p>It seems to have worked, or at least got passed that part.
  Shouldn't this function be appending that part itself?</p>
  
  <pre><code>-(NSString*) applicationDocumentsDirectory
  {
      return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
  }
  </code></pre>
  
  <p>It works fine in the simulator, what is the right practice?</p>