Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//
// SqliteInitialize.h
//
// Created by haoyayoi on 09/05/02.
// Copyright 2009 haoyayoi. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface SqliteInitialize : NSObject {
}
+ (SqliteInitialize *)setup;
+ (NSString *)writebleDBPath:(NSString *)sqlname;
- (BOOL)copyDB:(NSString *)sqlname;
@end
@implementation SqliteInitialize
+ (SqliteInitialize *)setup {
return [[[SqliteInitialize alloc] init] autorelease];
}
+ (NSString *)writebleDBPath:(NSString *)sqlname {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory stringByAppendingPathComponent:sqlname];
}
- (BOOL)copyDB:(NSString *)sqlname {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSString *writableDBPath = [SqliteInitialize writebleDBPath];
BOOL success = [fileManager fileExistsAtPath:writableDBPath];
if(!success){
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:sqlname];
success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
}
return success;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.