title: iphone - coredata application directory
body: <p>I am using this Xcode template for core data. </p>
  
  <p>On the delegate, I have this method:</p>
  
  <pre><code>- (NSURL *)applicationDocumentsDirectory {
    return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
  }
  </code></pre>
  
  <p>but this requires iOS4.</p>
  
  <p>I am trying to make the app compatible with 3.0.</p>
  
  <p>So, I have converted this method to:</p>
  
  <pre><code>- (NSURL *)applicationDocumentsDirectory {
  
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    return [NSURL URLWithString:documentsDirectory];
  
  }
  </code></pre>
  
  <p>but when coredata tries to use the store URL on</p>
  
  <pre><code>  NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"MyFile.sqlite"];
    if (![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&amp;error]) {
  </code></pre>
  
  <p>it crashes on the IF line with the message:</p>
  
  <p><strong>CoreData SQL stores only support file URLs (got /var/mobile/Applications/BB312A7E-6AE1-4BA2-AD87-6B96D8855CC6/Documents/MyFile.sqlite).'</strong></p>
  
  <p>but StoreURL is a NSURL! </p>
  
  <p>Any clues? Thanks</p>