详解Sqlite如何在IOS开发中应用

移动开发 iOS
Sqlite如何在IOS开发中应用是本文要介绍的内容,主要是来学习在IOS开发中sqlite数据库的使用方法,具体内容来看本文详解。

Sqlite如何在IOS开发中应用是本文要介绍的内容,主要是来学习在IOS开发sqlite数据库的使用方法。sqlite数据库初始化,复制到用户目录,并判断是否数据库已经存在,或者复制是否成功!

在AppDelegate.m中输入以下代码,以便复制预置数据库到指定doucment目录

- (BOOL) initializeDb {  
NSLog (@"initializeDB");  
// look to see if DB is in known location (~/Documents/$DATABASE_FILE_NAME)  
//START:code.DatabaseShoppingList.findDocumentsDirectory  
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
NSString *documentFolderPath = [searchPaths objectAtIndex: 0];  
//查看文件目录  
NSLog(@"%@",documentFolderPath);  
dbFilePath = [documentFolderPath stringByAppendingPathComponent:@"shopping.db"];  
//END:code.DatabaseShoppingList.findDocumentsDirectory  
[dbFilePath retain];  
//START:code.DatabaseShoppingList.copyDatabaseFileToDocuments  
if (! [[NSFileManager defaultManager] fileExistsAtPath: dbFilePath]) {  
// didn't find db, need to copy  
NSString *backupDbPath = [[NSBundle mainBundle] pathForResource:@"shopping" ofType:@"db"];  
if (backupDbPath == nil) {  
// couldn't find backup db to copy, bail  
return NO;  
} else {  
BOOL copiedBackupDb = [[NSFileManager defaultManager] copyItemAtPath:backupDbPath toPath:dbFilePath error:nil];  
if (! copiedBackupDb) {  
// copying backup db failed, bail  
return NO;  
}  
}  
}  
return YES;  
//END:code.DatabaseShoppingList.copyDatabaseFileToDocuments  
NSLog (@"bottom of initializeDb");  
}  
- (void)applicationDidFinishLaunching:(UIApplication *)application {  
// copy the database from the bundle if necessary  
if (! [self initializeDb]) {  
// TODO: alert the user!  
NSLog (@"couldn't init db");  
return;  
}  
    // Add the tab bar controller's current view as a subview of the window  
    [window addSubview:tabBarController.view];  

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.

小结:详解Sqlite如何在IOS开发中应用的内容介绍完了,希望本文能对你有所帮助!

责任编辑:zhaolei 来源: 新浪博客
相关推荐

2011-09-02 19:12:59

IOS应用Sqlite数据库

2013-04-09 16:04:06

iOS开发SQLite知识总结

2013-01-06 09:52:43

SQLite

2011-07-27 10:16:41

iPhone SQLite 数据库

2013-05-02 13:06:05

C++遇到iOS应用开SQLITE

2011-08-17 14:20:21

IOS开发GraphicsCon

2011-08-17 14:30:34

iOS开发窗口

2013-04-01 10:49:51

iOS开发sqlite数据库

2011-07-04 17:45:45

Qt Sqlite 数据库

2011-08-17 15:10:21

iPhone开发Web视图

2013-01-06 12:23:59

Android开发SQLite数据库

2011-09-06 16:44:47

IOS应用SQLite

2011-08-10 17:37:00

iPhoneASIHTTPRequ

2021-05-07 15:36:50

iOS隐藏应用程序

2011-08-15 11:13:06

IOS开发并发Dispatch Qu

2021-07-02 20:37:19

Python代码SRP

2009-06-02 10:02:50

eclipse jboeclipse jbojboss for e

2020-03-31 21:50:41

JavaScript前端技术

2022-07-15 09:01:15

React对象编程

2009-04-29 16:05:23

Oracle连接输出SQL
点赞
收藏

51CTO技术栈公众号