當前位置:
首頁 >
将外部准备好的sqlite导入到项目当中
發(fā)布時間:2024/1/17
41
豆豆
生活随笔
收集整理的這篇文章主要介紹了
将外部准备好的sqlite导入到项目当中
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
首先,將sqlite數(shù)據(jù)庫文件放在Resource文件夾下,并且允許其編譯到項目當中。
之后在AppDelegate當中執(zhí)行一些代碼,這里將代碼封裝了一個Helper:
1 #import "RPDBInitializeHelper.h" 2 3 @implementation RPDBInitializeHelper 4 5 + (void)initializeDatabase { 6 NSString *dbPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/db.sqlite"]; 7 if (![[NSFileManager defaultManager] fileExistsAtPath:dbPath]) { 8 NSString *dbResourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"db.sqlite"]; 9 [[NSFileManager defaultManager] copyItemAtPath:dbResourcePath toPath:dbPath error:nil]; 10 } 11 } 12 13 @end首先到沙盒的Documents目錄下查找是否存在數(shù)據(jù)庫文件,如果不存在,則從資源文件當中復(fù)制過去。
轉(zhuǎn)載于:https://www.cnblogs.com/Steak/p/3764395.html
總結(jié)
以上是生活随笔為你收集整理的将外部准备好的sqlite导入到项目当中的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C#中JSON的理解
- 下一篇: centos自启动脚本