IOS 数据存储

iOS本地数据存储安全 iOS本地数据存储安全移动APP通常会在设备本地存储一些数据,这可以为程序执行、更良好地性能或离线访问提供支持。由于移动设备使用地越来越广泛,设备失窃的风险也越来越大,因此不安全的本地数据存储已成为移动APP安全的主要威胁之一。攻击者可以通过一些方式获取到存储在iOS设备上的敏感信息,主要有以下方法: 恶意程序 借助iOS系统的安全弱点,攻击者可以设计出一种远程偷取iPhone上文件的恶意程序。 阅读详情

ios数据存储包括以下几种存储机制:

属性列表

对象归档

SQLite3

CoreData

AppSettings

普通文件存储

1、属性列表

[cpp]  view plain copy
  1. //  
  2. //  Persistence1ViewController.h  
  3. //  Persistence1  
  4. //  
  5. //  Created by liu lavy on 11-10-3.  
  6. //  Copyright 2011 __MyCompanyName__. All rights reserved.  
  7. //  
  8.   
  9. #import <UIKit/UIKit.h>  
  10. #define kFilename @"data.plist"  
  11.   
  12. @interface Persistence1ViewController : UIViewController {  
  13.     UITextField *filed1;  
  14.     UITextField *field2;  
  15.     UITextField *field3;  
  16.     UITextField *field4;  
  17. }  
  18. @property (nonatomic, retain) IBOutlet UITextField *field1;  
  19. @property (nonatomic, retain) IBOutlet UITextField *field2;  
  20. @property (nonatomic, retain) IBOutlet UITextField *field3;  
  21. @property (nonatomic, retain) IBOutlet UITextField *field4;  
  22.   
  23. - (NSString *)dataFilePath;  
  24. - (void)applicationWillResignActive:(NSNotification *)notification;  
  25.   
  26. @end  

[cpp]  view plain copy
  1. //  
  2. //  Persistence1ViewController.m  
  3. //  Persistence1  
  4. //  
  5. //  Created by liu lavy on 11-10-3.  
  6. //  Copyright 2011 __MyCompanyName__. All rights reserved.  
  7. //  
  8.   
  9. #import "Persistence1ViewController.h"  
  10.   
  11. @implementation Persistence1ViewController  
  12. @synthesize field1;  
  13. @synthesize field2;  
  14. @synthesize field3;  
  15. @synthesize field4;  
  16.   
  17. //数据文件的完整路径  
  18. - (NSString *)dataFilePath {  
  19.     //检索Documents目录路径。第二个参数表示将搜索限制在我们的应用程序沙盒中  
  20.     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
  21.     //每个应用程序只有一个Documents目录  
  22.     NSString *documentsDirectory = [paths objectAtIndex:0];  
  23.     //创建文件名  
  24.     return [documentsDirectory stringByAppendingPathComponent:kFilename];  
  25. }  
  26.   
  27. //应用程序退出时,将数据保存到属性列表文件  
  28. - (void)applicationWillResignActive:(NSNotification *)notification {  
  29.     NSMutableArray *array = [[NSMutableArray alloc] init];  
  30.     [array addObject: field1.text];  
  31.     [array addObject: field2.text];  
  32.     [array addObject: field3.text];  
  33.     [array addObject: field4.text];  
  34.     [array writeToFile:[self dataFilePath] atomically:YES];  
  35.     [array release];  
  36. }  
  37.   
  38. /* 
  39. // The designated initializer. Override to perform setup that is required before the view is loaded. 
  40. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 
  41.     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
  42.     if (self) { 
  43.         // Custom initialization 
  44.     } 
  45.     return self; 
  46. } 
  47. */  
  48.   
  49. /* 
  50. // Implement loadView to create a view hierarchy programmatically, without using a nib. 
  51. - (void)loadView { 
  52. } 
  53. */  
  54.   
  55.   
  56.   
  57. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.  
  58. - (void)viewDidLoad {  
  59.     [super viewDidLoad];  
  60.     NSString *filePath = [self dataFilePath];  
  61.     //检查数据文件是否存在  
  62.     if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {  
  63.         NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];  
  64.         field1.text = [array objectAtIndex:0];  
  65.         field2.text = [array objectAtIndex:1];  
  66.         field3.text = [array objectAtIndex:2];  
  67.         field4.text = [array objectAtIndex:3];  
  68.         [array release];  
  69.     }  
  70.     UIApplication *app = [UIApplication sharedApplication];  
  71.     [[NSNotificationCenter defaultCenter] addObserver:self  
  72.                                             selector:@selector(applicationWillResignActive:)  
  73.                                             name:UIApplicationWillResignActiveNotification  
  74.                                             object:app];  
  75.     [super viewDidLoad];  
  76. }  
  77.   
  78.   
  79. /* 
  80. // Override to allow orientations other than the default portrait orientation. 
  81. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
  82.     // Return YES for supported orientations 
  83.     return (interfaceOrientation == UIInterfaceOrientationPortrait); 
  84. } 
  85. */  
  86.   
  87. - (void)didReceiveMemoryWarning {  
  88.     // Releases the view if it doesn't have a superview.  
  89.     [super didReceiveMemoryWarning];  
  90.       
  91.     // Release any cached data, images, etc that aren't in use.  
  92. }  
  93.   
  94. - (void)viewDidUnload {  
  95.     self.field1 = nil;  
  96.     self.field2 = nil;  
  97.     self.field3 = nil;  
  98.     self.field4 = nil;  
  99.     [super viewDidUnload];  
  100. }  
  101.   
  102.   
  103. - (void)dealloc {  
  104.     [field1 release];  
  105.     [field2 release];  
  106.     [field3 release];  
  107.     [field4 release];  
  108.     [super dealloc];  
  109. }  
  110.   
  111. @end  

===================================================================================

===================================================================================

2、对象归档

[cpp]  view plain copy
  1. //  
  2. //  Fourlines.h  
  3. //  Persistence2  
  4. //  
  5. //  Created by liu lavy on 11-10-3.  
  6. //  Copyright 2011 __MyCompanyName__. All rights reserved.  
  7. //  
  8.   
  9. #import <Foundation/Foundation.h>  
  10.   
  11. @interface Fourlines : NSObject <NSCoding, NSCopying> {  
  12.     NSString *field1;  
  13.     NSString *field2;  
  14.     NSString *field3;  
  15.     NSString *field4;  
  16. }  
  17. @property (nonatomic, retain) NSString *field1;  
  18. @property (nonatomic, retain) NSString *field2;  
  19. @property (nonatomic, retain) NSString *field3;  
  20. @property (nonatomic, retain) NSString *field4;  
  21.   
  22.   
  23. @end  

[cpp]  view plain copy
  1. //  
  2. //  Fourlines.m  
  3. //  Persistence2  
  4. //  
  5. //  Created by liu lavy on 11-10-3.  
  6. //  Copyright 2011 __MyCompanyName__. All rights reserved.  
  7. //  
  8.   
  9. #import "Fourlines.h"  
  10.   
  11. #define kField1Key @"Field1"  
  12. #define kField2Key @"Field2"  
  13. #define kField3Key @"Field3"  
  14. #define kField4Key @"Field4"  
  15.   
  16. @implementation Fourlines  
  17. @synthesize field1;  
  18. @synthesize field2;  
  19. @synthesize field3;  
  20. @synthesize field4;  
  21.   
  22. #pragma mark NSCoding  
  23. - (void)encodeWithCoder:(NSCoder *)aCoder {  
  24.     [aCoder encodeObject:field1 forKey:kField1Key];  
  25.     [aCoder encodeObject:field2 forKey:kField2Key];  
  26.     [aCoder encodeObject:field3 forKey:kField3Key];  
  27.     [aCoder encodeObject:field4 forKey:kField4Key];  
  28. }  
  29.   
  30. -(id) initWithCoder:(NSCoder *)aDecoder {  
  31.     if(self = [super init]) {  
  32.         field1 = [[aDecoder decodeObjectForKey:kField1Key] retain];  
  33.         field2 = [[aDecoder decodeObjectForKey:kField2Key] retain];  
  34.         field3 = [[aDecoder decodeObjectForKey:kField3Key] retain];  
  35.         field4 = [[aDecoder decodeObjectForKey:kField4Key] retain];  
  36.     }  
  37.     return self;  
  38. }  
  39.   
  40. #pragma mark -  
  41. #pragma mark NSCopying  
  42. - (id) copyWithZone:(NSZone *)zone {  
  43.     Fourlines *copy = [[[self class] allocWithZone: zone] init];  
  44.     copy.field1 = [[self.field1 copyWithZone: zone] autorelease];  
  45.     copy.field2 = [[self.field2 copyWithZone: zone] autorelease];  
  46.     copy.field3 = [[self.field3 copyWithZone: zone] autorelease];  
  47.     copy.field4 = [[self.field4 copyWithZone: zone] autorelease];  
  48.     return copy;  
  49. }  
  50. @end  

[cpp]  view plain copy
  1. //  
  2. //  Persistence2ViewController.h  
  3. //  Persistence2  
  4. //  
  5. //  Created by liu lavy on 11-10-3.  
  6. //  Copyright 2011 __MyCompanyName__. All rights reserved.  
  7. //  
  8.   
  9. #import <UIKit/UIKit.h>  
  10. #define kFilename @"archive"  
  11. #define kDataKey @"Data"  
  12.   
  13. @interface Persistence2ViewController : UIViewController {  
  14.     UITextField *filed1;  
  15.     UITextField *field2;  
  16.     UITextField *field3;  
  17.     UITextField *field4;  
  18. }  
  19. @property (nonatomic, retain) IBOutlet UITextField *field1;  
  20. @property (nonatomic, retain) IBOutlet UITextField *field2;  
  21. @property (nonatomic, retain) IBOutlet UITextField *field3;  
  22. @property (nonatomic, retain) IBOutlet UITextField *field4;  
  23.   
  24. - (NSString *)dataFilePath;  
  25. - (void)applicationWillResignActive:(NSNotification *)notification;  
  26.   
  27. @end  

[cpp]  view plain copy
  1. //  
  2. //  Persistence2ViewController.m  
  3. //  Persistence2  
  4. //  
  5. //  Created by liu lavy on 11-10-3.  
  6. //  Copyright 2011 __MyCompanyName__. All rights reserved.  
  7. //  
  8.   
  9. #import "Persistence2ViewController.h"  
  10. #import "Fourlines.h"  
  11.   
  12. @implementation Persistence2ViewController  
  13. @synthesize field1;  
  14. @synthesize field2;  
  15. @synthesize field3;  
  16. @synthesize field4;  
  17.   
  18. //数据文件的完整路径  
  19. - (NSString *)dataFilePath {  
  20.     //检索Documents目录路径。第二个参数表示将搜索限制在我们的应用程序沙盒中  
  21.     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
  22.     //每个应用程序只有一个Documents目录  
  23.     NSString *documentsDirectory = [paths objectAtIndex:0];  
  24.     //创建文件名  
  25.     return [documentsDirectory stringByAppendingPathComponent:kFilename];  
  26. }  
  27.   
  28. //应用程序退出时,将数据保存到属性列表文件  
  29. - (void)applicationWillResignActive:(NSNotification *)notification {  
  30.     Fourlines *fourlines = [[Fourlines alloc] init];  
  31.     fourlines.field1 = field1.text;  
  32.     fourlines.field2 = field2.text;  
  33.     fourlines.field3 = field3.text;  
  34.     fourlines.field4 = field4.text;  
  35.       
  36.     NSMutableData *data = [[NSMutableData alloc] init];//用于存储编码的数据  
  37.     NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];  
  38.       
  39.     [archiver encodeObject:fourlines forKey:kDataKey];  
  40.     [archiver finishEncoding];  
  41.     [data writeToFile:[self dataFilePath] atomically:YES];  
  42.       
  43.     [fourlines release];  
  44.     [archiver release];  
  45.     [data release];  
  46. }  
  47.   
  48. /* 
  49.  // The designated initializer. Override to perform setup that is required before the view is loaded. 
  50.  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 
  51.  self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
  52.  if (self) { 
  53.  // Custom initialization 
  54.  } 
  55.  return self; 
  56.  } 
  57.  */  
  58.   
  59. /* 
  60.  // Implement loadView to create a view hierarchy programmatically, without using a nib. 
  61.  - (void)loadView { 
  62.  } 
  63.  */  
  64.   
  65.   
  66.   
  67. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.  
  68. - (void)viewDidLoad {  
  69.     [super viewDidLoad];  
  70.     NSString *filePath = [self dataFilePath];  
  71.     //检查数据文件是否存在  
  72.     if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {  
  73.           
  74.         //从文件获取用于解码的数据  
  75.         NSData *data = [[NSMutableData alloc] initWithContentsOfFile:[self dataFilePath]];  
  76.         NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];  
  77.           
  78.         Fourlines *fourlines = [unarchiver decodeObjectForKey:kDataKey];  
  79.         [unarchiver finishDecoding];  
  80.           
  81.         field1.text = fourlines.field1;  
  82.         field2.text = fourlines.field2;  
  83.         field3.text = fourlines.field3;  
  84.         field4.text = fourlines.field4;  
  85.           
  86.         [unarchiver release];  
  87.         [data release];  
  88.     }  
  89.     UIApplication *app = [UIApplication sharedApplication];  
  90.     [[NSNotificationCenter defaultCenter] addObserver:self  
  91.                                              selector:@selector(applicationWillResignActive:)  
  92.                                              name:UIApplicationWillResignActiveNotification  
  93.                                              object:app];  
  94.     [super viewDidLoad];  
  95. }  
  96.   
  97.   
  98. /* 
  99.  // Override to allow orientations other than the default portrait orientation. 
  100.  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
  101.  // Return YES for supported orientations 
  102.  return (interfaceOrientation == UIInterfaceOrientationPortrait); 
  103.  } 
  104.  */  
  105.   
  106. - (void)didReceiveMemoryWarning {  
  107.     // Releases the view if it doesn't have a superview.  
  108.     [super didReceiveMemoryWarning];  
  109.       
  110.     // Release any cached data, images, etc that aren't in use.  
  111. }  
  112.   
  113. - (void)viewDidUnload {  
  114.     self.field1 = nil;  
  115.     self.field2 = nil;  
  116.     self.field3 = nil;  
  117.     self.field4 = nil;  
  118.     [super viewDidUnload];  
  119. }  
  120.   
  121.   
  122. - (void)dealloc {  
  123.     [field1 release];  
  124.     [field2 release];  
  125.     [field3 release];  
  126.     [field4 release];  
  127.     [super dealloc];  
  128. }  
  129. @end  


===================================================================================

===================================================================================


3、SQLite

[cpp]  view plain copy
  1. //  
  2. //  Persistence3ViewController.h  
  3. //  Persistence3  
  4. //  
  5. //  Created by liu lavy on 11-10-3.  
  6. //  Copyright 2011 __MyCompanyName__. All rights reserved.  
  7. //  
  8.   
  9. #import <UIKit/UIKit.h>  
  10. #define kFilename @"data.sqlite3"  
  11.   
  12. @interface Persistence3ViewController : UIViewController {  
  13.     UITextField *filed1;  
  14.     UITextField *field2;  
  15.     UITextField *field3;  
  16.     UITextField *field4;  
  17. }  
  18. @property (nonatomic, retain) IBOutlet UITextField *field1;  
  19. @property (nonatomic, retain) IBOutlet UITextField *field2;  
  20. @property (nonatomic, retain) IBOutlet UITextField *field3;  
  21. @property (nonatomic, retain) IBOutlet UITextField *field4;  
  22.   
  23. - (NSString *)dataFilePath;  
  24. - (void)applicationWillResignActive:(NSNotification *)notification;  
  25. @end  

[cpp]  view plain copy
  1. //  
  2. //  Persistence3ViewController.m  
  3. //  Persistence3  
  4. //  
  5. //  Created by liu lavy on 11-10-3.  
  6. //  Copyright 2011 __MyCompanyName__. All rights reserved.  
  7. //  
  8.   
  9. #import "Persistence3ViewController.h"  
  10. #import <sqlite3.h>  
  11.   
  12. @implementation Persistence3ViewController  
  13. @synthesize field1;  
  14. @synthesize field2;  
  15. @synthesize field3;  
  16. @synthesize field4;  
  17.   
  18. //数据文件的完整路径  
  19. - (NSString *)dataFilePath {  
  20.     //检索Documents目录路径。第二个参数表示将搜索限制在我们的应用程序沙盒中  
  21.     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
  22.     //每个应用程序只有一个Documents目录  
  23.     NSString *documentsDirectory = [paths objectAtIndex:0];  
  24.     //创建文件名  
  25.     return [documentsDirectory stringByAppendingPathComponent:kFilename];  
  26. }  
  27.   
  28. //应用程序退出时,将数据保存到属性列表文件  
  29. - (void)applicationWillResignActive:(NSNotification *)notification {  
  30.     sqlite3 *database;  
  31.     if(sqlite3_open([[self dataFilePath] UTF8String], &database) != SQLITE_OK) {  
  32.         sqlite3_close(database);  
  33.         NSAssert(0, @"Failed to open database");  
  34.     }  
  35.       
  36.     for(int i = 1; i <= 4; i++) {  
  37.         NSString *fieldname = [[NSString alloc] initWithFormat:@"field%d", i];  
  38.         UITextField *field = [self valueForKey:fieldname];  
  39.         [fieldname release];  
  40.           
  41.         char *update = "INSERT OR REPLACE INTO FIELDS (ROW, FIELD_DATA) VALUES (?, ?);";  
  42.         sqlite3_stmt *stmt;  
  43.         //将SQL语句编译为sqlite内部一个结构体(sqlite3_stmt),类似java JDBC的PreparedStatement预编译  
  44.         if (sqlite3_prepare_v2(database, update, -1, &stmt, nil) == SQLITE_OK) {  
  45.             //在bind参数的时候,参数列表的index从1开始,而取出数据的时候,列的index是从0开始  
  46.             sqlite3_bind_int(stmt, 1, i);  
  47.             sqlite3_bind_text(stmt, 2, [field.text UTF8String], -1, NULL);  
  48.         } else {  
  49.             NSAssert(0, @"Error:Failed to prepare statemen");  
  50.         }  
  51.         //执行SQL文,获取结果   
  52.         int result = sqlite3_step(stmt);  
  53.         if(result != SQLITE_DONE) {  
  54.             NSAssert1(0, @"Error updating table: %d", result);  
  55.         }  
  56.         //释放stmt占用的内存(sqlite3_prepare_v2()分配的)  
  57.         sqlite3_finalize(stmt);  
  58.     }  
  59.     sqlite3_close(database);  
  60. }  
  61.   
  62. /* 
  63.  // The designated initializer. Override to perform setup that is required before the view is loaded. 
  64.  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 
  65.  self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
  66.  if (self) { 
  67.  // Custom initialization 
  68.  } 
  69.  return self; 
  70.  } 
  71.  */  
  72.   
  73. /* 
  74.  // Implement loadView to create a view hierarchy programmatically, without using a nib. 
  75.  - (void)loadView { 
  76.  } 
  77.  */  
  78.   
  79.   
  80.   
  81. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.  
  82. - (void)viewDidLoad {  
  83.     [super viewDidLoad];  
  84.     NSString *filePath = [self dataFilePath];  
  85.     //检查数据文件是否存在  
  86.     if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {  
  87.         //打开数据库  
  88.         sqlite3 *database;  
  89.         if(sqlite3_open([filePath UTF8String], &database) != SQLITE_OK) {  
  90.             sqlite3_close(database);  
  91.             NSAssert(0, @"Failed to open database");  
  92.         }  
  93.           
  94.         //创建表  
  95.         char *errorMsg;  
  96.         NSString *createSQL =   
  97.             @"CREATE TABLE IF NOT EXISTS FIELDS (ROW INTEGER PRIMARY KEY, FIELD_DATA TEXT);";  
  98.         if(sqlite3_exec(database, [createSQL UTF8String], NULL, NULL, &errorMsg) != SQLITE_OK) {  
  99.             sqlite3_close(database);  
  100.             NSAssert(0, @"Error creating table: %s", errorMsg);  
  101.         }  
  102.   
  103.         //查询  
  104.         NSString *query = @"SELECT ROW, FIELD_DATA FROM FIELDS ORDER BY ROW";  
  105.         sqlite3_stmt *statement;  
  106.         //设置nByte可以加速操作  
  107.         if(sqlite3_prepare_v2(database, [query UTF8String], -1, &statement, nil) == SQLITE_OK) {  
  108.             while (sqlite3_step(statement) == SQLITE_ROW) {//返回每一行  
  109.                 int row = sqlite3_column_int(statement, 0);  
  110.                 char *rowData = (char *)sqlite3_column_text(statement, 1);  
  111.                   
  112.                 NSString *fieldName = [[NSString alloc] initWithFormat:@"field%d", row];  
  113.                 NSString *fieldValue = [[NSString alloc] initWithUTF8String:rowData];  
  114.                   
  115.                 UITextField *field = [self valueForKey:fieldName];  
  116.                 field.text = fieldValue;  
  117.                   
  118.                 [fieldName release];  
  119.                 [fieldValue release];  
  120.             }  
  121.             //释放statement占用的内存(sqlite3_prepare()分配的)  
  122.             sqlite3_finalize(statement);  
  123.         }  
  124.         sqlite3_close(database);  
  125.     }  
  126.       
  127.       
  128.     UIApplication *app = [UIApplication sharedApplication];  
  129.     [[NSNotificationCenter defaultCenter] addObserver:self  
  130.                                              selector:@selector(applicationWillResignActive:)  
  131.                                                  name:UIApplicationWillResignActiveNotification  
  132.                                                object:app];  
  133.     [super viewDidLoad];  
  134. }  
  135.   
  136.   
  137. /* 
  138.  // Override to allow orientations other than the default portrait orientation. 
  139.  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
  140.  // Return YES for supported orientations 
  141.  return (interfaceOrientation == UIInterfaceOrientationPortrait); 
  142.  } 
  143.  */  
  144.   
  145. - (void)didReceiveMemoryWarning {  
  146.     // Releases the view if it doesn't have a superview.  
  147.     [super didReceiveMemoryWarning];  
  148.       
  149.     // Release any cached data, images, etc that aren't in use.  
  150. }  
  151.   
  152. - (void)viewDidUnload {  
  153.     self.field1 = nil;  
  154.     self.field2 = nil;  
  155.     self.field3 = nil;  
  156.     self.field4 = nil;  
  157.     [super viewDidUnload];  
  158. }  
  159.   
  160.   
  161. - (void)dealloc {  
  162.     [field1 release];  
  163.     [field2 release];  
  164.     [field3 release];  
  165.     [field4 release];  
  166.     [super dealloc];  
  167. }  
  168.   
  169. @end  

===================================================================================

===================================================================================

4、Core Data

[cpp]  view plain copy
  1. //  
  2. //  PersistenceViewController.h  
  3. //  Persistence4  
  4. //  
  5. //  Created by liu lavy on 11-10-3.  
  6. //  Copyright 2011 __MyCompanyName__. All rights reserved.  
  7. //  
  8.   
  9. #import <UIKit/UIKit.h>  
  10.   
  11.   
  12. @interface PersistenceViewController : UIViewController {  
  13.     UITextField *filed1;  
  14.     UITextField *field2;  
  15.     UITextField *field3;  
  16.     UITextField *field4;  
  17. }  
  18. @property (nonatomic, retain) IBOutlet UITextField *field1;  
  19. @property (nonatomic, retain) IBOutlet UITextField *field2;  
  20. @property (nonatomic, retain) IBOutlet UITextField *field3;  
  21. @property (nonatomic, retain) IBOutlet UITextField *field4;  
  22.   
  23. @end  

[cpp]  view plain copy
  1. //  
  2. //  PersistenceViewController.m  
  3. //  Persistence4  
  4. //  
  5. //  Created by liu lavy on 11-10-3.  
  6. //  Copyright 2011 __MyCompanyName__. All rights reserved.  
  7. //  
  8.   
  9. #import "PersistenceViewController.h"  
  10. #import "Persistence4AppDelegate.h"  
  11.   
  12. @implementation PersistenceViewController  
  13. @synthesize field1;  
  14. @synthesize field2;  
  15. @synthesize field3;  
  16. @synthesize field4;  
  17.   
  18.   
  19. -(void) applicationWillResignActive:(NSNotification *)notification {  
  20.     Persistence4AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];  
  21.     NSManagedObjectContext *context = [appDelegate managedObjectContext];  
  22.     NSError *error;  
  23.     for(int i = 1; i <= 4; i++) {  
  24.         NSString *fieldName = [NSString stringWithFormat:@"field%d", i];  
  25.         UITextField *theField = [self valueForKey:fieldName];  
  26.           
  27.         //创建提取请求  
  28.         NSFetchRequest *request = [[NSFetchRequest alloc] init];  
  29.         //创建实体描述并关联到请求  
  30.         NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Line"  
  31.                                                              inManagedObjectContext:context];  
  32.         [request setEntity:entityDescription];  
  33.           
  34.         //设置检索数据的条件  
  35.         NSPredicate *pred = [NSPredicate predicateWithFormat:@"(lineNum = %d)", i];  
  36.         [request setPredicate:pred];  
  37.           
  38.         NSManagedObject *theLine = nil;  
  39.         ////检查是否返回了标准匹配的对象,如果有则加载它,如果没有则创建一个新的托管对象来保存此字段的文本  
  40.         NSArray *objects = [context executeFetchRequest:request error:&error];  
  41.         if(!objects) {  
  42.             NSLog(@"There was an error");  
  43.         }  
  44.         //if(objects.count > 0) {  
  45.         //  theLine = [objects objectAtIndex:0];  
  46.         //} else {  
  47.             //创建一个新的托管对象来保存此字段的文本  
  48.             theLine = [NSEntityDescription insertNewObjectForEntityForName:@"Line"  
  49.                                                     inManagedObjectContext:context];  
  50.             [theLine setValue:[NSNumber numberWithInt:i] forKey:@"lineNum"];  
  51.             [theLine setValue:theField.text forKey:@"lineText"];  
  52.         //}  
  53.         [request release];  
  54.     }  
  55.     //通知上下文保存更改  
  56.     [context save:&error];  
  57.       
  58. }  
  59.   
  60. // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.  
  61. /* 
  62. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 
  63.     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
  64.     if (self) { 
  65.         // Custom initialization. 
  66.     } 
  67.     return self; 
  68. } 
  69. */  
  70.   
  71.   
  72. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.  
  73. - (void)viewDidLoad {  
  74.     Persistence4AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];  
  75.       
  76.     NSManagedObjectContext *context = [appDelegate managedObjectContext];  
  77.     //创建一个实体描述  
  78.     NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Line" inManagedObjectContext:context];  
  79.     //创建一个请求,用于提取对象  
  80.     NSFetchRequest *request = [[NSFetchRequest alloc] init];  
  81.     [request setEntity:entityDescription];  
  82.       
  83.     //检索对象  
  84.     NSError *error;  
  85.     NSArray *objects = [context executeFetchRequest:request error:&error];  
  86.     if(!objects) {  
  87.         NSLog(@"There was an error!");  
  88.     }  
  89.     for(NSManagedObject *obj in objects) {  
  90.         NSNumber *lineNum = [obj valueForKey:@"lineNum"];  
  91.         NSString *lineText = [obj valueForKey:@"lineText"];  
  92.         NSString *fieldName = [NSString stringWithFormat:@"field%d", [lineNum integerValue]];  
  93.         UITextField *textField = [self valueForKey:fieldName];  
  94.         textField.text = lineText;  
  95.     }  
  96.     [request release];  
  97.       
  98.     UIApplication *app = [UIApplication sharedApplication];  
  99.     [[NSNotificationCenter defaultCenter] addObserver:self   
  100.                                              selector:@selector(applicationWillResignActive:)   
  101.                                                  name:UIApplicationWillResignActiveNotification  
  102.                                                object:app];  
  103.     [super viewDidLoad];  
  104. }  
  105.   
  106. /* 
  107. // Override to allow orientations other than the default portrait orientation. 
  108. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
  109.     // Return YES for supported orientations. 
  110.     return (interfaceOrientation == UIInterfaceOrientationPortrait); 
  111. } 
  112. */  
  113.   
  114. - (void)didReceiveMemoryWarning {  
  115.     // Releases the view if it doesn't have a superview.  
  116.     [super didReceiveMemoryWarning];  
  117.       
  118.     // Release any cached data, images, etc. that aren't in use.  
  119. }  
  120.   
  121. - (void)viewDidUnload {  
  122.     self.field1 = nil;  
  123.     self.field2 = nil;  
  124.     self.field3 = nil;  
  125.     self.field4 = nil;  
  126.     [super viewDidUnload];  
  127. }  
  128.   
  129.   
  130. - (void)dealloc {  
  131.     [field1 release];  
  132.     [field2 release];  
  133.     [field3 release];  
  134.     [field4 release];  
  135.     [super dealloc];  
  136. }  
  137.   
  138.   
  139.   
  140. @end  

5、AppSettings

[cpp]  view plain copy
  1. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];  

===================================================================================

===================================================================================

6、普通文件存储

这种方式即自己将数据通过IO保存到文件,或从文件读取。


声明:此篇所有代码来自《Iphone4与IPad开发基础教程》

【iOS-Android开发对比】之 数据存储 Android与iOS开发对比系列】之 数据存储 相比Android和iOS,我觉得Android的数据存储更开放一些。Android天生就可以使用多Java I/O;并且天生开放的特性,开发者可以直接在SD卡中读写文件,自由度比较高。缺点吗,也是因为太开放,所以Android的相册和文件夹都惨不忍睹。Android本身自带Java的反射和注解,很早就有了ORM数据库。这里解释一下,ORM 阅读详情

相关推荐

手机安装Kali Linux

在数字化时代,信息安全和隐私保护显得尤为重要。,作为一款专业的和工具,因其强大的功能和丰富的资源库而受到广大安全研究者和爱好者的青睐。然而,我们通常只能在传统的电脑设备上安装和使用Kali Linux。那么,有没有可能将也变成一款随身携带的Kali Linux设备呢?答案是肯定的。本文将介绍如何在手机上安装Kali Linux,使你的手机变成一款强大的移动安全工具。,我们需要明确一点,手机安装Kali Linux并非简单的操作,需要对手机进行一定的改造和配置。

2301_80124151的博客 6979

iOS数据存储

iOS数据存储有如下5种方式: 1、plist文件(属性列表) 2、preference (偏好设置) 3、NSKeyedArchiver (归档) 4、SQLite 3 5、CoreData 在讲解以上几种存储方式之前,我们需要先了解应用程序中的文件结构,其中最主要的是沙盒机制。 每个应用程序都会有一个独立的沙盒,相当于一个容器,用于存放一些信息,

MarsCWD的博客 612

ZEMAX学习第7天-手机镜头光学系统设计全过程案例

接下来对系统微调,依次缩小CRA和畸变,首先对CRA进行依次递减(39°、38°、37°、36°、35°),目前CRA角度40度,每次下降一度进行优化,利用MAXX加OPLT一起控制,控制小于35°。可以看出在标注的三个地方镜头曲率变化,导致PY=1的光线走向奇特,因此需要对矢高进行调整,按照标注的地方依次调整(从右到左)至传函变好,越靠近右边对其余视场影响越小。3.圆锥系数值较大,透镜形状怪异;一、第1,3镜子偏厚,第4镜子偏薄,45镜子间隔边缘偏小,第5片镜子中心厚度与边缘厚度相差较大,需要控制;

liningliwei的博客 1099

iOS 应用数据存储

iOS 开发中,经常会有将数据存储到本地的需求。比如一些数据的缓存,或者记录下用户的账号密码,记录下下次是否自动登录等,这些都需要将数据记录到本地。iOS中,数据存储到本地的常见方式有三种: 一: 使用plist 存储到本地; 二:Preference(偏好设置) 三:归档解档。 举例介绍一下三种方式。 在介绍数据存储之前,需要先了解下iOS 中app的沙盒机制,详情

xiewenyu_c的博客 1041

手把手教你校准垂起固定翼(VTOL)遥控器与电调:从零到飞的完整流程

本文详细介绍了垂起固定翼(VTOL)遥控器与电调的校准流程,从基础认知到飞行前检查,涵盖遥控器通道配置、电调校准、舵机方向调整等关键步骤。通过图文并茂的指导,帮助无人机爱好者安全完成VTOL调试,确保首飞成功。特别强调多旋翼模式、过渡模式和固定翼模式的设置要点,适合新手和进阶用户参考。

jenkins8butler的博客 364

从手机到单片机:聊聊ARM Cortex家族那些事,A、R、M系列到底有啥不同?

本文深入解析ARM Cortex家族的A、R、M三大系列处理器,揭示它们在性能、实时响应和能效方面的核心差异。从智能手机到汽车电子和物联网设备,Cortex-A、R、M各司其职,分别应对复杂运算、实时控制和超低功耗场景。通过技术指标对比和典型应用案例,帮助开发者理解如何根据DMIPS/MHz等关键参数选择适合的处理器架构。

weixin_31574149的博客 354

点进来你就懂的iOS数据存储

转载本文需注明出处:微信公众号EAWorld,违者必究。沙盒(英语:sandbox,又译为沙箱),计算机术语,在计算机安全领域中是一种安全机制,为运行中的程序提供的隔离环境。通常是作为一...

低代码开发,数据,中间件,企业架构原创技术分享 845

UFAST车道线检测 Ultra-Fast-Lane-Detection 从环境搭建到复现完成(一)

UFAST车道线检测 Ultra-Fast-Lane-Detection 从环境搭建到复现完成(一)

m0_46364958的博客 4347

iOS 四种数据存储对比

你是用什么方法来持久保存数据的?这是在几乎每一次关于iOS技术的交流或讨论都会被提到的问题,而且大家对这个问题的热情持续高涨。本文主要从概念上把“数据存储”这个问题进行剖析,并且结合各自特点和适用场景给大家提供一个选择的思路,并不详细介绍某一种方式的技术细节。 谈到数据储存,首先要明确区分两个概念,数据结构和储存方式。所谓数据结构就是数据存在的形式。除了基本的NSDictionary、NSArr

vaercly的专栏 1487

11、体内皮质功能的电压敏感染料成像技术

本文详细介绍了电压敏感染料成像(VSDI)技术在体内皮质功能研究中的应用。内容涵盖VSDI的技术起源、作用机制、信号特点与解读局限性,以及其在映射感觉皮质功能区方面的优势。文章对比了VSDI与电极记录和钙成像技术的差异,突出了其在高时空分辨率下监测神经元群体亚阈值活动的独特价值。同时,提供了完整的实验操作流程,包括手术步骤、染料应用、光学系统配置及数据分析方法,并总结了常见问题及其解决方案。随着基因靶向和多模态技术结合的发展,VSDI有望进一步提升信号特异性和空间精度,成为解析大脑网络动态的重要工具。

Apple的专栏 90

OpenClaw简介--windows系统安装OpenClaw

在windows安装OpenClaw实现代替人工操作。步骤流程详细,图文并茂。

直到世界的尽头 5359

IOS 数据存储的区别

在iOS开发过程中,不管是做什么应用,都会碰到数据保存的问题。将数据保存到本地,能够让程序的运行更加流畅,不会出现让人厌恶的菊花形状,使得用户体验更好。下面介绍一下数据保存的方式:   1.NSKeyedArchiver:采用归档的形式来保存数据,该数据对象需要遵守NSCoding协议,并且该对象对应的类必须提供encodeWithCoder:和initWithCoder:方法。前一个方法告诉系

花露朝阳的专栏 418

第 13 章:Spring AI Alibaba MCP 与 Nacos3 — 企业级MCP服务

理解Spring AI Alibaba 框架下的MCP服务与Nacos注册中心整合的必要性,学会Spring AI Alibaba-基于Nacos的MCP实现方法

paopao_wu的专栏 791

iOS数据存储的四种方案对比

你是用什么方法来持久保存数据的?这是在几乎每一次关于iOS技术的交流或讨论都会被提到的问题,而且大家对这个问题的热情持续高涨。本文主要从概念上把“数据存储”这个问题进行剖析,并且结合各自特点和适用场景给大家提供一个选择的思路,并不详细介绍某一种方式的技术细节。 谈到数据储存,首先要明确区分两个概念,数据结构和储存方式。所谓数据结构就是数据存在的形式。除了基本的NSDictionary、NSA

coder 进阶的专栏 2573

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

IOS数据存储5种方式

iOS中的数据存储(上) iOS应用数据存储的常用方式: 应用沙盒: 应用沙盒结构分析 Documents: temp: Library/Caches: Library/Preference: 沙盒根路径: 属性列表 偏好设置(Preference) NSKeyedArchiver NSData iOS中的数据存储(上) iOS应用数据存储的常用

zhangqq16781的博客 783

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

iOS开发简单高效的数据存储

学习交流讨论请关注新浪微博:极客James在iOS开发过程中,不管是做什么应用,都会碰到数据保存的问题,你是用什么方法来持久保存数据的?这是在几乎每一次关于iOS技术的交流或讨论都会被提到的问题,而且大家对这个问题的热情持续高涨。本文主要从概念上把“数据存储”这个问题进行剖析,并且结合各自特点和适用场景进行全面抛析。。一、NSUserDefaultsNSUserDefaults被设计用来存储设备和应

求知若渴,虚心若愚,努力前行,未来可期。 3562

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

iOS开发之数据存储

一、iOS应用数据存储的常用方式- XML属性列表(plist)归档 - Preference(偏好设置) 本质还是通过“plist”来存储数据, 但是使用更简单(无需关注文件、文件夹路径和名称) - NSKeyedArchiver归档(NSCoding) 把任何对象, 直接保存为文件的方式。 - SQLite3 当非常大量的数据存储时使用 - Core Data 就是对SQLite的封装 二、

weishinexk的博客 565

ios数据存储

下面总结下之前遇到的ios数据存储中的经验总结. 5.0以后,用户可以选择将程序备份到icloud,这对沙盒内的数据存储有了新的要求。 开启icloud备份后,程序内容可以备份到云端,这样用户数据可以在其他i设备上使用。这样,开发人员在沙盒中存储数据就有讲究了。直接上Apple的文档。 下面简单翻译一下。 icloud和itunes对以下三个文件夹不会备份: /AppName.app

*冷鹰* 762

[ios] 关于iOS 的几种数据存储模式

开篇点题。 http://blog.csdn.net/tianyitianyi1/article/details/7713103        我也是参考了这个人的博文才更加深入了解了数据存储模式。理论部分我就不在这里赘述了。 下面谈一谈我的理解。 我们可以再进一步把数据存储模式细分一下,可以分为如下几类: 1 XML属性列表(plist)归档 2 Preference(偏

xczbvc的专栏 551

iOS开发中本地数据存储的总结

iOS开发中本地数据存储的总结 字数1896 阅读3772 评论0 喜欢22 iOS开发中本地存储主要有三种形式 XML属性列表(plist)归档Preference(偏好设置)NSKeyedArchiver归档(NSCoding) 应用沙盒 什么是应用沙盒 要想在本地存储数据,那就要知道一下什么是应用沙盒 ,其实很好理解应用沙盒就是应用的文

csdn_woshishui的博客 324

iOS 常用四种数据存储方式

iOS 常用四种数据存储方式 在iOS开发过程中,不管是做什么应用,都会碰到数据保存的问题。将数据保存到本地,能够让程序的运行更加流畅, ,使得用户体验更好。下面介绍⼀一下数据保存的方式: 1.NSKeyedArchiver:采用归档的形式来保存数据,该数据对象需要遵守NSCoding协议,并且该对象对应的类必须提 供encodeWithCoder:和initWithCoder:方法。前⼀一个方法告诉系统怎么对对象进行编码,而后⼀一个方法则是告诉系统怎么对对象进行解码。例如对Possession对象

Eduora_meimei的专栏 2440
上一篇: IOS开发UI篇之──自定义加载等待框(MBProgressHUD)
下一篇: IOS多线程开发之GCD
simbi
博客等级 码龄22年 86粉丝 24原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址