iOS中四种最常用的将数据持久存储在iOS文件系统的机制

前三种机制的相同点都是需要找到沙盒里面的Documents的目录路径,附加自己相应的文件名字符串来生成需要的完整路径,再往里面创建、读取、写入文件

而第四种则是与委托有关,下面给出代码(有修改过的部分)。

这里做的示例是用四个TextField来显示内容,如图

一、属性列表(.plist)

  1. //
  2. // ViewController.m
  3. // Persistence
  4. //
  5. // Created by Kim Topley on 7/31/14.
  6. // Copyright (c) 2014 Apress. All rights reserved.
  7. //
  8.  
  9. #import "ViewController.h"
  10.  
  11. @interface ViewController ()
  12.  
  13. @property (strong, nonatomic) IBOutletCollection(UITextField) NSArray *lineFields;
  14.  
  15. @end
  16.  
  17. @implementation ViewController
  18.  
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. // Do any additional setup after loading the view, typically from a nib.
  22.  
  23. NSString *filePath = [self dataFilePath];
  24. if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
  25. NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];
  26. for (int i = ; i < ; i++) {
  27. UITextField *theField = self.lineFields[i];
  28. theField.text = array[i];
  29. }
  30. }
  31.  
  32. UIApplication *app = [UIApplication sharedApplication];
  33. [[NSNotificationCenter defaultCenter]
  34. addObserver:self
  35. selector:@selector(applicationWillResignActive:)
  36. name:UIApplicationWillResignActiveNotification
  37. object:app];
  38. }
  39.  
  40. - (void)applicationWillResignActive:(NSNotification *)notification {
  41. NSString *filePath = [self dataFilePath];
  42. NSArray *array = [self.lineFields valueForKey:@"text"];
  43. [array writeToFile:filePath atomically:YES];
  44. }
  45.  
  46. - (void)didReceiveMemoryWarning {
  47. [super didReceiveMemoryWarning];
  48. // Dispose of any resources that can be recreated.
  49. }
  50.  
  51. - (NSString *)dataFilePath
  52. {
  53. NSArray *paths = NSSearchPathForDirectoriesInDomains(
  54. NSDocumentDirectory, NSUserDomainMask, YES);
  55. NSString *documentsDirectory = [paths objectAtIndex:];
  56. return [documentsDirectory stringByAppendingPathComponent:@"data.plist"];
  57. }
  58. @end

ViewController.m

二、对象归档

1、遵循NSCoding协议

2、遵循NSCopying协议

3、对数据对象进行归档和取消归档

  1. //
  2. // FourLines.h
  3. // Persistence
  4. //
  5. // Created by Jierism on 16/7/27.
  6. // Copyright © 2016年 Jierism. All rights reserved.
  7. //
  8.  
  9. #import <Foundation/Foundation.h>
  10.  
  11. @interface FourLines : NSObject<NSCoding,NSCopying>
  12.  
  13. @property(copy,nonatomic)NSArray *lines;
  14.  
  15. @end

FourLines.h

  1. //
  2. // FourLines.m
  3. // Persistence
  4. //
  5. // Created by Jierism on 16/7/27.
  6. // Copyright © 2016年 Jierism. All rights reserved.
  7. //
  8.  
  9. #import "FourLines.h"
  10.  
  11. static NSString * const kLinesKey = @"kLinesKey";
  12.  
  13. @implementation FourLines
  14.  
  15. #pragma mark - Coding
  16. // 回复我们之前归档的对象
  17. - (instancetype)initWithCoder:(NSCoder *)aDecoder
  18. {
  19. self = [super init];
  20. if (self) {
  21. self.lines = [aDecoder decodeObjectForKey:kLinesKey];
  22. }
  23. return self;
  24. }
  25.  
  26. // 将所有实例变成编码成aCoder
  27. - (void)encodeWithCoder:(NSCoder *)aCoder
  28. {
  29. [aCoder encodeObject:self.lines forKey:kLinesKey];
  30. }
  31.  
  32. #pragma mark - Copying
  33.  
  34. - (id)copyWithZone:(NSZone *)zone
  35. {
  36. // 新建一个新的FourLines对象,并将字符串数组复制进去
  37. FourLines *copy = [[[self class] allocWithZone:zone] init];
  38. NSMutableArray *linesCopy = [NSMutableArray array];
  39. for ( id line in self.lines) {
  40. [linesCopy addObject:[line copyWithZone:zone]];
  41. }
  42. copy.lines = linesCopy;
  43. return copy;
  44. }
  45.  
  46. @end

FourLines.m

  1. //
  2. // ViewController.m
  3. // Persistence
  4. //
  5. // Created by Jierism on 16/7/27.
  6. // Copyright © 2016年 Jierism. All rights reserved.
  7. //
  8.  
  9. #import "ViewController.h"
  10. #import "FourLines.h"
  11.  
  12. static NSString * const kRootKey = @"kRootKey";
  13. @interface ViewController ()
  14.  
  15. @property(strong,nonatomic)IBOutletCollection(UITextField) NSArray *lineFields;
  16.  
  17. @end
  18.  
  19. @implementation ViewController
  20.  
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. // Do any additional setup after loading the view, typically from a nib.
  24.  
  25. NSString *filePath = [self dataFilePath];
  26. if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
  27.  
  28. // 从归档中重组对象,对数据进行解码
  29. NSData *data = [[NSMutableData alloc] initWithContentsOfFile:filePath];
  30. NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
  31. FourLines *foueLines = [unarchiver decodeObjectForKey:kRootKey];
  32. [unarchiver finishDecoding];
  33.  
  34. for (int i = ; i < ; i++) {
  35. UITextField *theFiled = self.lineFields[i];
  36. theFiled.text = foueLines.lines[i];
  37. }
  38.  
  39. }
  40.  
  41. // 订阅,获取通知
  42. UIApplication *app = [UIApplication sharedApplication];
  43. [[NSNotificationCenter defaultCenter] addObserver:self
  44. selector:@selector(applicationWillResignActive:)
  45. name:UIApplicationWillResignActiveNotification
  46. object:app];
  47. }
  48.  
  49. // 接收通知,告诉应用在终止运行或者进入后台之前保存数据
  50. - (void) applicationWillResignActive:(NSNotification *)notification
  51. {
  52. NSString *filePath = [self dataFilePath];
  53.  
  54. // 将对象归档到data实例中
  55. FourLines *fourLines = [[FourLines alloc] init];
  56. fourLines.lines = [self.lineFields valueForKey:@"text"];
  57. NSMutableData *data = [[NSMutableData alloc] init];
  58. NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
  59. [archiver encodeObject:fourLines forKey:kRootKey];
  60. [archiver finishEncoding];
  61. [data writeToFile:filePath atomically:YES];
  62. }
  63.  
  64. - (void)didReceiveMemoryWarning {
  65. [super didReceiveMemoryWarning];
  66. // Dispose of any resources that can be recreated.
  67. }
  68.  
  69. // 获取数据文件的完整路径(两步)
  70. - (NSString *)dataFilePath
  71. {
  72. //1.查找Documents目录
  73. NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  74. NSString *documentsDirectory = [path objectAtIndex:];
  75. //2.在后面附加数据文件的文件名
  76. return [documentsDirectory stringByAppendingPathComponent:@"data.archive"];
  77. }
  78.  
  79. @end

ViewController.m

三、iOS的嵌入式关系数据库SQLite3

链接到数据库

在项目导航面板中顶部选中项目名称,按下图操作即可

1、创建或打开数据库

2、绑定变量

  1. //
  2. // ViewController.m
  3. // SQLite Persistence
  4. //
  5. // Created by Jierism on 16/7/27.
  6. // Copyright © 2016年 Jierism. All rights reserved.
  7. //
  8.  
  9. #import "ViewController.h"
  10. #import <sqlite3.h>
  11.  
  12. @interface ViewController ()
  13.  
  14. @property (strong,nonatomic) IBOutletCollection(UITextField) NSArray *lineFields;
  15.  
  16. @end
  17.  
  18. @implementation ViewController
  19.  
  20. - (NSString *)dataFilePath
  21. {
  22. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  23. NSString *documentsDirectory = [paths objectAtIndex:];
  24. return [documentsDirectory stringByAppendingString:@"data.sqlite"];
  25. }
  26.  
  27. // 数据库在应用打开时才打开用于加载数据,加载完毕后会关闭
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. // Do any additional setup after loading the view, typically from a nib.
  31.  
  32. // 打开数据库,如果在打开时遇到问题则关闭,并抛出断言错误
  33. sqlite3 *database;
  34. if (sqlite3_open([[self dataFilePath] UTF8String],&database) != SQLITE_OK) {
  35. sqlite3_close(database);
  36. NSAssert(, @"Failed to open database");
  37. }
  38.  
  39. // 建立一个表来保存我们的数据,用IF NOT可以防止数据库覆盖现有数据:如果已有相同名的表则此命令不执行操作
  40. NSString *createSQL = @"CREATE TABLE IF NOT EXISTS FIELDS "
  41. "(ROW INTEGER PRIMAY KEY,FIELD_DATA TEXT);";
  42. char *errorMsg;
  43. if (sqlite3_exec (database,[createSQL UTF8String],NULL,NULL,&errorMsg) != SQLITE_OK) {
  44. sqlite3_close(database);
  45. NSAssert(, @"Error creating table:%s",errorMsg);
  46. }
  47.  
  48. // 数据库中没一行包含一个整型(从0计数)和一个字符串(对应行的内容),加载内容
  49. NSString *query = @"SELECT ROW,FIELD_DATA FROM FIELDS ORDER BY ROW";
  50. sqlite3_stmt *statement;
  51. if (sqlite3_prepare_v2(database,[query UTF8String],-,&statement,nil) == SQLITE_OK) {
  52. // 遍历返回的每一行
  53. while (sqlite3_step(statement) == SQLITE_ROW) {
  54. // 抓取行号存储在一个int变量中,抓取字段数据保存在char类型的字符串中
  55. int row = sqlite3_column_int(statement,);
  56. char *rowData = (char *)sqlite3_column_text(statement,);
  57. // 利用从数据库中获取的值设置相应的字段
  58. NSString *fieldValue = [[NSString alloc] initWithUTF8String:rowData];
  59. UITextField *field = self.lineFields[row];
  60. field.text = fieldValue;
  61. }
  62. // 关闭数据库连接
  63. sqlite3_finalize(statement);
  64. }
  65. sqlite3_close(database);
  66.  
  67. UIApplication *app = [UIApplication sharedApplication];
  68. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:app];
  69.  
  70. }
  71.  
  72. - (void)applicationWillResignActive:(NSNotification *)notification
  73. {
  74. // 打开数据库
  75. sqlite3 *database;
  76. if (sqlite3_open([[self dataFilePath] UTF8String], &database) != SQLITE_OK) {
  77. sqlite3_close(database);
  78. NSAssert(, @"Failed to open database");
  79. }
  80.  
  81. // 遍历数据库每一行,更新里面的数据
  82. for (int i = ; i < ; i++) {
  83. UITextField *field = self.lineFields[i];
  84. char *update = "INSERT OR REPLACE INTO FIELDS (ROW,FIELD_DATA)"
  85. "VALUES(?,?)";
  86. char *errorMsg = NULL;
  87.  
  88. // 声明一个指向语句的指针,然后为语句添加绑定变量,并将值绑定到两个绑定变量
  89. sqlite3_stmt *stmt;
  90. if (sqlite3_prepare_v2(database, update, -, &stmt, nil) == SQLITE_OK) {
  91. sqlite3_bind_int(stmt,,i);
  92. sqlite3_bind_text(stmt,,[field.text UTF8String],-,NULL);
  93. }
  94. // 调用sqlite3_step来执行更新,检查并确定其运行正常,然后完成语句,结束循环
  95. if (sqlite3_step(stmt) != SQLITE_DONE) {
  96. NSAssert(, @"Error updating table:%s",errorMsg);
  97. }
  98. sqlite3_finalize(stmt);
  99. }
  100. // 关闭数据库
  101. sqlite3_close(database);
  102. }
  103.  
  104. @end

ViewController.m

四、苹果公司提供的持久化工具Core Data

1、键-值编码(KVC)

2、在上下文中结合

3、创建新的托管对象

4、获取托管对象

  1. //
  2. // AppDelegate.h
  3. // Core Data Persistance
  4. //
  5. // Created by Jierism on 16/7/27.
  6. // Copyright © 2016年 Jierism. All rights reserved.
  7. //
  8.  
  9. #import <UIKit/UIKit.h>
  10. #import <CoreData/CoreData.h>
  11.  
  12. @interface AppDelegate : UIResponder <UIApplicationDelegate>
  13.  
  14. @property (strong, nonatomic) UIWindow *window;
  15.  
  16. @property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
  17. @property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
  18. @property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
  19.  
  20. - (void)saveContext;
  21. - (NSURL *)applicationDocumentsDirectory;
  22.  
  23. @end

AppDelegate.h

  1. #pragma mark - Core Data stack
  2.  
  3. @synthesize managedObjectContext = _managedObjectContext;
  4. @synthesize managedObjectModel = _managedObjectModel;
  5. @synthesize persistentStoreCoordinator = _persistentStoreCoordinator;
  6.  
  7. - (NSURL *)applicationDocumentsDirectory {
  8. // The directory the application uses to store the Core Data store file. This code uses a directory named "jie.Core_Data_Persistance" in the application's documents directory.
  9. return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
  10. }
  11.  
  12. - (NSManagedObjectModel *)managedObjectModel {
  13. // The managed object model for the application. It is a fatal error for the application not to be able to find and load its model.
  14. if (_managedObjectModel != nil) {
  15. return _managedObjectModel;
  16. }
  17. NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"Core_Data_Persistance" withExtension:@"momd"];
  18. _managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
  19. return _managedObjectModel;
  20. }
  21.  
  22. - (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
  23. // The persistent store coordinator for the application. This implementation creates and returns a coordinator, having added the store for the application to it.
  24. if (_persistentStoreCoordinator != nil) {
  25. return _persistentStoreCoordinator;
  26. }
  27.  
  28. // Create the coordinator and store
  29.  
  30. _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
  31. NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Core_Data_Persistance.sqlite"];
  32. NSError *error = nil;
  33. NSString *failureReason = @"There was an error creating or loading the application's saved data.";
  34. if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
  35. // Report any error we got.
  36. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  37. dict[NSLocalizedDescriptionKey] = @"Failed to initialize the application's saved data";
  38. dict[NSLocalizedFailureReasonErrorKey] = failureReason;
  39. dict[NSUnderlyingErrorKey] = error;
  40. error = [NSError errorWithDomain:@"YOUR_ERROR_DOMAIN" code: userInfo:dict];
  41. // Replace this with code to handle the error appropriately.
  42. // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
  43. NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
  44. abort();
  45. }
  46.  
  47. return _persistentStoreCoordinator;
  48. }
  49.  
  50. - (NSManagedObjectContext *)managedObjectContext {
  51. // Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.)
  52. if (_managedObjectContext != nil) {
  53. return _managedObjectContext;
  54. }
  55.  
  56. NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
  57. if (!coordinator) {
  58. return nil;
  59. }
  60. _managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
  61. [_managedObjectContext setPersistentStoreCoordinator:coordinator];
  62. return _managedObjectContext;
  63. }
  64.  
  65. #pragma mark - Core Data Saving support
  66.  
  67. - (void)saveContext {
  68. NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
  69. if (managedObjectContext != nil) {
  70. NSError *error = nil;
  71. if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) {
  72. // Replace this implementation with code to handle the error appropriately.
  73. // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
  74. NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
  75. abort();
  76. }
  77. }
  78. }
  79.  
  80. @end

AppDelegate.m

  1. //
  2. // ViewController.m
  3. // Core Data Persistance
  4. //
  5. // Created by Jierism on 16/7/27.
  6. // Copyright © 2016年 Jierism. All rights reserved.
  7. //
  8.  
  9. #import "ViewController.h"
  10. #import "AppDelegate.h"
  11.  
  12. static NSString * const kLineEntityName = @"Line";
  13. static NSString * const kLineNumberKey = @"lineNumber";
  14. static NSString * const kLineTextKey = @"lineText";
  15.  
  16. @interface ViewController ()
  17.  
  18. @property (strong,nonatomic) IBOutletCollection(UITextField) NSArray *lineFields;
  19.  
  20. @end
  21.  
  22. @implementation ViewController
  23.  
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. // Do any additional setup after loading the view, typically from a nib.
  27.  
  28. // 获取对应用委托的引用,使用这个引用获得为我们创建的托管对象上下文
  29. AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
  30. NSManagedObjectContext *context = [appDelegate managedObjectContext];
  31.  
  32. // 创建一个获取请求并将实体描述传递给它,以便请求指导要检索的对象类型
  33. NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:kLineEntityName];
  34.  
  35. // 检索存储中所有Line对象,上下文返回库中每一个Line对象。确保返回的是有效数组,否则记录相应日志
  36. NSError *error;
  37. NSArray *objects = [context executeFetchRequest:request error:&error];
  38. if (objects == nil) {
  39. NSLog(@"There was an error!"); // 进行适当错误处理
  40. }
  41.  
  42. // 使用快熟枚举遍历已获取托管对象的数组,从中提取每个托管对象的lineNum和lineText的值,并用该信息更新用户界面上的文本框
  43. for (NSManagedObject *oneObject in objects) {
  44. int lineNum = [[oneObject valueForKey:kLineNumberKey] intValue];
  45. NSString *lineText = [oneObject valueForKey:kLineTextKey];
  46.  
  47. UITextField *theField = self.lineFields[lineNum];
  48. theField.text = lineText;
  49. }
  50.  
  51. // 在应用终止时获取通知,保存更改
  52. UIApplication *app = [UIApplication sharedApplication];
  53. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:app];
  54. }
  55.  
  56. - (void)applicationWillResignActive:(NSNotification *)notification
  57. {
  58.  
  59. // 与上面一样,获取对应用委托的引用,使用引用获取指向应用的默认托管对象上下文的指针
  60. AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
  61. NSManagedObjectContext *context = [appDelegate managedObjectContext];
  62.  
  63. NSError *error;
  64.  
  65. // 获得每一个字段对应的索引
  66. for (int i = ; i < ; i++) {
  67. UITextField *theField = self.lineFields[i];
  68.  
  69. // 为Line实体创建获取请求,创建一个谓词确认存储中是否已经有一个与这个字段对应的托管对象
  70. NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:kLineEntityName];
  71. NSPredicate *pred = [NSPredicate predicateWithFormat:@"(%K = %d)",kLineNumberKey,i]; // 谓词
  72. [request setPredicate:pred];
  73.  
  74. // 在上下文中执行后去请求,并检查objects是否为nil
  75.  
  76. NSArray *objects = [context executeFetchRequest:request error:&error];
  77. if (objects == nil) {
  78. NSLog(@"There was an error!");
  79. }
  80.  
  81. // 声明一个指向NSManagedObject的指针并设置为nil。因为我们不知道要从持久存储中加载托管对象,还是创建新的托管对象。
  82. // 因此,可以检查与条件匹配的返回对象。如果返回有效的对象就进行加载,否则就创建一个新的托管对象来保存这个字段的文本
  83. NSManagedObject *theLine = nil;
  84. if ([objects count] > ) {
  85. theLine = [objects objectAtIndex:];
  86. }else{
  87. theLine = [NSEntityDescription insertNewObjectForEntityForName:kLineEntityName inManagedObjectContext:context];
  88. }
  89.  
  90. // 使用键-值编码(KVC)来设置行号以及此托管对象的文本
  91. [theLine setValue:[NSNumber numberWithInt:i] forKey:kLineNumberKey];
  92. [theLine setValue:theField.text forKey:kLineTextKey];
  93. }
  94. // 完成循环,保存更改
  95. [appDelegate saveContext];
  96. }
  97.  
  98. @end

ViewController.m

iOS开发-数据持久化的更多相关文章

  1. IOS开发--数据持久化篇之文件存储(一)

    前言:个人觉得开发人员最大的悲哀莫过于懂得使用却不明白其中的原理.在代码之前我觉得还是有必要简单阐述下相关的一些知识点. 因为文章或深或浅总有适合的人群.若有朋友发现了其中不正确的观点还望多多指出,不 ...

  2. IOS开发--数据持久化篇文件存储(二)

    前言:个人觉得开发人员最大的悲哀莫过于懂得使用却不明白其中的原理.在代码之前我觉得还是有必要简单阐述下相关的一些知识点. 因为文章或深或浅总有适合的人群.若有朋友发现了其中不正确的观点还望多多指出,不 ...

  3. iOS开发——数据持久化Swift篇&使用Core Data进行数据持久化存储

    使用Core Data进行数据持久化存储   一,Core Data介绍 1,Core Data是iOS5之后才出现的一个数据持久化存储框架,它提供了对象-关系映射(ORM)的功能,即能够将对象转化成 ...

  4. iOS开发——数据持久化Swift篇&(一)NSUserDefault

    NSUserDefault //******************** 5.1 NSUserDefault和对象归档 func useNSUserDefault() { //通过单利来创建一个NSU ...

  5. iOS开发——数据持久化Swift篇&文件目录路径获取(Home目录,文档目录,缓存目录等)

    文件目录路径获取(Home目录,文档目录,缓存目录等)   iOS应用程序只能在自己的目录下进行文件的操作,不可以访问其他的存储空间,此区域被称为沙盒.下面介绍常用的程序文件夹目录:   1,Home ...

  6. iOS开发——数据持久化Swift篇&iCloud云存储

    iCloud云存储 import UIKit class ViewController: UIViewController { override func viewDidLoad() { super. ...

  7. iOS开发——数据持久化OC篇&plist文件增删改查操作

    Plist文件增删查改   主要操作: 1.//获得plist路径    -(NSString*)getPlistPath: 2.//判断沙盒中名为plistname的文件是否存在    -(BOOL ...

  8. iOS开发——数据持久化Swift篇&(四)CoreData

    CoreData import CoreData class ViewController: UIViewController { override func viewDidLoad() { supe ...

  9. iOS开发——数据持久化Swift篇&(三)SQLite3

    SQLite3 使用 //******************** 5.3 SQLite3存储和读取数据 func use_SQLite3() { //声明一个Documents下的路径 var db ...

随机推荐

  1. Android、iPhone和Java三个平台一致的加密工具

    先前一直在做安卓,最近要开发iPhone客户端,这其中遇到的最让人纠结的要属Java.Android和iPhone三个平台加解密不一致的问题. 因为手机端后台通常是用JAVA开发的Web Servic ...

  2. Xcode中如何启用或禁用某些文件的ARC

    经常会有工程中涉及到第三方的代码, 但这些代码有的是ARC的, 有的不是. 这样的话, 在与你的工程中集成的时候就会出现问题. 如果你的工程是开启ARC的, 那就需要对某些文件禁用ARC, (-fno ...

  3. SQL Server 2005的XML数据修改语言(XML DML)

    转:http://www.microsoft.com/china/msdn/library/data/sqlserver/XMLDML.mspx?mfr=true 作为对XQuery语言的扩展,XML ...

  4. ubuntu鼠标突然不能使用的解决方法

    今天发现鼠标(usb即插即用)不能用了,最后发现需要接通充电才可以!!!用电池的时候居然不可以用鼠标?

  5. java AES加密算法

    package com.siro.tools; import javax.crypto.Cipher;import javax.crypto.spec.IvParameterSpec;import j ...

  6. 1047图的深度优先遍历c语言

    描述 图(graph)是数据结构 G=(V,E),其中V是G中结点的有限非空集合,结点的偶对称为边(edge):E是G中边的有限集合.设V={0,1,2,……,n-1},图中的结点又称为顶点(vert ...

  7. acdream 1056 (黑白染色)

    题意:给你一些关系,每个关系是两只马的名字,表示这两个马不能在一个分组里,问你能否将这些马分成两组. 黑白染色,相邻的点染不同颜色.bfs搞即可,水题. /* * this code is made ...

  8. Tableau学习笔记之二

    2张图片解析下Tableau 9.0界面的功能 1.数据加载界面: 2.数据分析界面:

  9. netty的入门

    netty是什么? netty是一个基于NIO的通信框架,对于传统计算机,系统的瓶颈一直在输入输出设备上,计算速度超过IO速度,所以对于i o的性能提高异常重要. 什么是NIO? 非阻塞IO,N表示n ...

  10. Leetcode Largest Number c++ solution

    Total Accepted: 16020 Total Submissions: 103330     Given a list of non negative integers, arrange t ...