Я пытаюсь удалить файл из пути, используя следующий код.Но мое приложение падает при удалении файла из пути.
- (void)saveEditedSavedFile:(NSString*)editedfile As:(NSString*)originalFile
{
[originalFile retain];
NSArray* dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* docsDir = [dirPaths objectAtIndex:0];
NSError* error = nil;
NSString *editedFilePath=[docsDir stringByAppendingPathComponent:editedfile];
NSFileManager* fileMngr = [NSFileManager defaultManager];
if([fileMngr fileExistsAtPath:originalFile])
{
nslog(@"%@", originalFile); // nslog always prints the correct path even if it crashes..
[fileMngr removeItemAtPath:originalFile error:NULL];
}
if ([fileMngr moveItemAtPath:editedFilePath toPath:originalFile error:&error] != YES)
{
UIAlertView* alertView1 = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Unable to Save File. Please Choose a Diffrent name." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alertView1 show];
[alertView1 release];
}
}
Здесь я пытаюсь заменить уже существующий файл новым файлом (перемещение файловой операции), но происходит сбой в [fileMngr removeItemAtPath:ошибка originalFile: NULL];
Я получаю стек вызовов, подобный этому.
#0 0x99f1dc5a in __kill ()
#1 0x99f1dc4c in kill$UNIX2003 ()
#2 0x99fb05a5 in raise ()
#3 0x99fc66e4 in abort ()
#4 0x99fb4e78 in szone_error ()
#5 0x99fb4fb3 in free_list_checksum_botch ()
#6 0x99ec7a88 in small_free_list_remove_ptr ()
#7 0x99ec45cc in szone_free_definite_size ()
#8 0x99ec35e8 in free ()
#9 0x99ee8adb in fts_close$INODE64 ()
#10 0x99f31b57 in __removefile_tree_walker ()
#11 0x99f31999 in removefile ()
#12 0x0006ed01 in -[NSFilesystemItemRemoveOperation main] ()
#13 0x0005cbd2 in -[__NSOperationInternal start] ()
#14 0x0006eaa2 in -[NSFileManager removeItemAtPath:error:] ()
Может кто-нибудь сообщить мне, почему происходит сбой моего приложения?я проверил, что этот путь там правильный.