IPhone: delete / delete SQLite database?

I know how to create a sqlite database, insert data into it, delete a row in it, etc. using iPhone development, but I'm trying to completely delete the entire database, but not getting any hints. Please someone help me delete / delete the whole sqlite database from the device via code.

Thanks!

+6
source share
5 answers

Whether the database file is in the document directory and not in the Bundle, you can use NSFileManager to delete the file. Make sure it is not open by any progress.

0
source

If your db is in the docs, you can try:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *filePath =  [documentsDirectory stringByAppendingPathComponent:@"youdb.db"]; if([[NSFileManager defaultManager] fileExistsAtPath:filePath]){ [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil]; } 
+16
source

Try

 NSError *err; NSFileManager *fm = [NSFileManager defaultManager]; err = nil; NSString *deleteFileName = [NSString stringWithFormat:@"%@/FileName",[[NSBundle mainBundle] resourcePath]]; NSURL *url = [NSURL fileURLWithPath:deleteFileName]; [fm removeItemAtPath:[url path] error:&err]; if(err) { NSLog(@"File Manager: %@ %d %@", [err domain], [err code], [[err userInfo] description]); } else { NSLog(@"File %@ deleted.",fileName); } 
+1
source

If you use Xamarin in Visual Studio, this will work well.

 string _FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "databaseFileName.db3"); File.Delete(_FileName); 
+1
source

If you want to delete the entire database, you need to find it in the file system and delete it there.

0
source

Source: https://habr.com/ru/post/885488/


All Articles