开发者

NSFileManager createDirectoryAtPath EXC_BAD_ACCESS

开发者 https://www.devze.com 2023-02-09 05:02 出处:网络
I have been working at this one for quite some time now but can\'t seem to resolve it. I have a core data application that also supports document sharing, therefore I\'m trying to create a directory i

I have been working at this one for quite some time now but can't seem to resolve it. I have a core data application that also supports document sharing, therefore I'm trying to create a directory in the library folder for the sqlite db.

- (NSURL *)applicationPrivateDocumentsDirectory {
   NSString *libraryDirectory = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject];
   NSString *privateDocs = [libraryDire开发者_如何学运维ctory stringByAppendingPathComponent:@"PrivateDocuments"];
   NSFileManager *fileMgr = [[NSFileManager alloc] init];
   if (![fileMgr fileExistsAtPath:privateDocs]) {
      NSLog(@"Does not exist");
      NSError *error;
      [fileMgr createDirectoryAtPath:privateDocs withIntermediateDirectories:YES attributes:nil error:&error];
      NSLog(@"%@", [error description]);
   }
   NSURL *retURL = [NSURL fileURLWithPath:privateDocs];
   return retURL;
}

The debug console outputs "Does not exist" followed by "EXC_BAD_ACCESS"

Any help is greatly appreciated.


Try to add this: NSError *error = nil;

0

精彩评论

暂无评论...
验证码 换一张
取 消