title: How to unzip file and copy database from it in iOS?
body: <p>i am newbie and first to try unzip file, i want to unzip my database contain file and copy database from it for this i try like as</p>
  
  <p>In my <code>DBManager.m</code>  file i write like as</p>
  
  <pre><code>@interface DBManager()
  
  @property (nonatomic, strong) NSString *documentsDirectory;
  
  @property (nonatomic, strong) NSString *databaseFilename;
  
  @property (nonatomic, strong) NSMutableArray *arrResults;
  
  @end
  
  -(instancetype)initWithDatabaseFilename:(NSString *)dbFilename{
  self = [super init];
  if (self)
  {
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      self.documentsDirectory = [paths objectAtIndex:0];
      self.databaseFilename = dbFilename;
      [self copyDatabaseIntoDocumentsDirectory];
  }
  return self;
  }
  </code></pre>
  
  <p>For unzip file I write like as,</p>
  
  <pre><code>#pragma mark - Private method implementation
  -(void)copyDatabaseIntoDocumentsDirectory
  {
  NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
  
  NSString *zipFilePath = [documentsDirectory stringByAppendingPathComponent:@"sampledb.zip"];
  
  NSString *output = [documentsDirectory stringByAppendingPathComponent:self.documentsDirectory];
  
  ZipArchive* za = [[ZipArchive alloc] init];
  
  if( [za UnzipOpenFile:zipFilePath] )
  {
      if( [za UnzipFileTo:output overWrite:YES] != NO )
      {
          NSLog(@"Archive unzip success");
      }
  
      [za UnzipCloseFile];
  }
  NSString *destinationPath = [self.documentsDirectory stringByAppendingPathComponent:self.databaseFilename];
  if (![[NSFileManager defaultManager] fileExistsAtPath:destinationPath])
  {
      NSString *sourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:self.databaseFilename];
      NSError *error;
      [[NSFileManager defaultManager] copyItemAtPath:sourcePath toPath:destinationPath error:&amp;error];
      if (error != nil) {
          NSLog(@"%@", [error localizedDescription]);
      }
  }
  }
  </code></pre>
  
  <p>And in my <code>ViewController</code> class <code>ViewDidLoad</code> I write code for copy database like as</p>
  
  <pre><code>- (void)viewDidLoad
  {
  [super viewDidLoad];
  self.dbManager = [[DBManager alloc] initWithDatabaseFilename:@"sampledb.sql"];
  }
  </code></pre>
  
  <p>But my Database is not copied from zip file Please give me solution for it.
  Here <code>sampledb.zip</code> is my zip file and <code>sampledb.sql</code> is my database file in my zip file. i use <code>ZipArchive</code> from github to unzip file.</p>