dimanche 24 mai 2015

How check database exist or not

I could download FMDB for using in Swift.

I create one class for my database now I want add one function in my database class for checking sqlite file in DocumentDirectory.

I do this in Objective-C with this code:

#define DataName @"DeliDB.db"

- (NSString*)DatabasePath{
  NSArray *Paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  NSString *DocumentDir = [Paths objectAtIndex:0];
  //NSLog(@"%@",DocumentDir);
  return [DocumentDir stringByAppendingPathComponent:DataName];
}
- (void)checkDataBase{
  BOOL success;
  NSFileManager *fileManager = [NSFileManager defaultManager];
  success = [fileManager fileExistsAtPath:[self DatabasePath]];
  NSString *FileDB = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:DataName];
  if (success) {
    NSLog(@"File Exist");
    return;
  } else {
    [fileManager copyItemAtPath:FileDB toPath:[self DatabasePath] error:nil];
    NSLog(@"Data Base Copied!!!");
  }
}

now I want one function that do this in Swift!!! guide me about that....

Aucun commentaire:

Enregistrer un commentaire