Как удалить файл, созданный в каталоге документов

Я создал файл базы данных, используя следующий код

// Get the documents directory
NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsDir = dirPaths[0];

// Build the path to the database file


databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent:@"MyDB.db"]];

Как я могу удалить файл «MyDB.db»?

Заранее спасибо.


person Teja Nandamuri    schedule 22.09.2014    source источник
comment
Пожалуйста, сделайте небольшой поиск, прежде чем задавать вопрос.   -  person rmaddy    schedule 23.09.2014


Ответы (1)


Вы можете удалить файл с помощью следующих

NSError *error;
if(![[NSFileManager defaultManager] removeItemAtPath:databasePath error:&error]) {
    NSLog(@"error while removing file: %@", error.localizedDescription);
}
person Daniele    schedule 22.09.2014