IOS 数据储存
IOS 数据存储
属性列表
对象归档
SQLite3
CoreData
AppSettings
普通文件存储
1、属性列表
- //
- // Persistence1ViewController.h
- // Persistence1
- //
- // Created by liu lavy on 11-10-3.
- // Copyright 2011 __MyCompanyName__. All rights reserved.
- //
- #import <UIKit/UIKit.h>
- #define kFilename @"data.plist"
- @interface Persistence1ViewController : UIViewController {
- UITextField *filed1;
- UITextField *field2;
- UITextField *field3;
- UITextField *field4;
- }
- @property (nonatomic, retain) IBOutlet UITextField *field1;
- @property (nonatomic, retain) IBOutlet UITextField *field2;
- @property (nonatomic, retain) IBOutlet UITextField *field3;
- @property (nonatomic, retain) IBOutlet UITextField *field4;
- - (NSString *)dataFilePath;
- - (void)applicationWillResignActive:(NSNotification *)notification;
- @end
- //
- // Persistence1ViewController.m
- // Persistence1
- //
- // Created by liu lavy on 11-10-3.
- // Copyright 2011 __MyCompanyName__. All rights reserved.
- //
- #import "Persistence1ViewController.h"
- @implementation Persistence1ViewController
- @synthesize field1;
- @synthesize field2;
- @synthesize field3;
- @synthesize field4;
- //数据文件的完整路径
- - (NSString *)dataFilePath {
- //检索Documents目录路径。第二个参数表示将搜索限制在我们的应用程序沙盒中
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- //每个应用程序只有一个Documents目录
- NSString *documentsDirectory = [paths objectAtIndex:0];
- //创建文件名
- return [documentsDirectory stringByAppendingPathComponent:kFilename];
- }
- //应用程序退出时,将数据保存到属性列表文件
- - (void)applicationWillResignActive:(NSNotification *)notification {
- NSMutableArray *array = [[NSMutableArray alloc] init];
- [array addObject: field1.text];
- [array addObject: field2.text];
- [array addObject: field3.text];
- [array addObject: field4.text];
- [array writeToFile:[self dataFilePath] atomically:YES];
- [array release];
- }
- /*
- // The designated initializer. Override to perform setup that is required before the view is loaded.
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- */
- /*
- // Implement loadView to create a view hierarchy programmatically, without using a nib.
- - (void)loadView {
- }
- */
- // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- - (void)viewDidLoad {
- [super viewDidLoad];
- NSString *filePath = [self dataFilePath];
- //检查数据文件是否存在
- if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
- NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];
- field1.text = [array objectAtIndex:0];
- field2.text = [array objectAtIndex:1];
- field3.text = [array objectAtIndex:2];
- field4.text = [array objectAtIndex:3];
- [array release];
- }
- UIApplication *app = [UIApplication sharedApplication];
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(applicationWillResignActive:)
- name:UIApplicationWillResignActiveNotification
- object:app];
- [super viewDidLoad];
- }
- /*
- // Override to allow orientations other than the default portrait orientation.
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
- // Return YES for supported orientations
- return (interfaceOrientation == UIInterfaceOrientationPortrait);
- }
- */
- - (void)didReceiveMemoryWarning {
- // Releases the view if it doesn't have a superview.
- [super didReceiveMemoryWarning];
- // Release any cached data, images, etc that aren't in use.
- }
- - (void)viewDidUnload {
- self.field1 = nil;
- self.field2 = nil;
- self.field3 = nil;
- self.field4 = nil;
- [super viewDidUnload];
- }
- - (void)dealloc {
- [field1 release];
- [field2 release];
- [field3 release];
- [field4 release];
- [super dealloc];
- }
- @end
===================================================================================
===================================================================================
2、对象归档
- //
- // Fourlines.h
- // Persistence2
- //
- // Created by liu lavy on 11-10-3.
- // Copyright 2011 __MyCompanyName__. All rights reserved.
- //
- #import <Foundation/Foundation.h>
- @interface Fourlines : NSObject <NSCoding, NSCopying> {
- NSString *field1;
- NSString *field2;
- NSString *field3;
- NSString *field4;
- }
- @property (nonatomic, retain) NSString *field1;
- @property (nonatomic, retain) NSString *field2;
- @property (nonatomic, retain) NSString *field3;
- @property (nonatomic, retain) NSString *field4;
- @end
- //
- // Fourlines.m
- // Persistence2
- //
- // Created by liu lavy on 11-10-3.
- // Copyright 2011 __MyCompanyName__. All rights reserved.
- //
- #import "Fourlines.h"
- #define kField1Key @"Field1"
- #define kField2Key @"Field2"
- #define kField3Key @"Field3"
- #define kField4Key @"Field4"
- @implementation Fourlines
- @synthesize field1;
- @synthesize field2;
- @synthesize field3;
- @synthesize field4;
- #pragma mark NSCoding
- - (void)encodeWithCoder:(NSCoder *)aCoder {
- [aCoder encodeObject:field1 forKey:kField1Key];
- [aCoder encodeObject:field2 forKey:kField2Key];
- [aCoder encodeObject:field3 forKey:kField3Key];
- [aCoder encodeObject:field4 forKey:kField4Key];
- }
- -(id) initWithCoder:(NSCoder *)aDecoder {
- if(self = [super init]) {
- field1 = [[aDecoder decodeObjectForKey:kField1Key] retain];
- field2 = [[aDecoder decodeObjectForKey:kField2Key] retain];
- field3 = [[aDecoder decodeObjectForKey:kField3Key] retain];
- field4 = [[aDecoder decodeObjectForKey:kField4Key] retain];
- }
- return self;
- }
- #pragma mark -
- #pragma mark NSCopying
- - (id) copyWithZone:(NSZone *)zone {
- Fourlines *copy = [[[self class] allocWithZone: zone] init];
- copy.field1 = [[self.field1 copyWithZone: zone] autorelease];
- copy.field2 = [[self.field2 copyWithZone: zone] autorelease];
- copy.field3 = [[self.field3 copyWithZone: zone] autorelease];
- copy.field4 = [[self.field4 copyWithZone: zone] autorelease];
- return copy;
- }
- @end
- //
- // Persistence2ViewController.h
- // Persistence2
- //
- // Created by liu lavy on 11-10-3.
- // Copyright 2011 __MyCompanyName__. All rights reserved.
- //
- #import <UIKit/UIKit.h>
- #define kFilename @"archive"
- #define kDataKey @"Data"
- @interface Persistence2ViewController : UIViewController {
- UITextField *filed1;
- UITextField *field2;
- UITextField *field3;
- UITextField *field4;
- }
- @property (nonatomic, retain) IBOutlet UITextField *field1;
- @property (nonatomic, retain) IBOutlet UITextField *field2;
- @property (nonatomic, retain) IBOutlet UITextField *field3;
- @property (nonatomic, retain) IBOutlet UITextField *field4;
- - (NSString *)dataFilePath;
- - (void)applicationWillResignActive:(NSNotification *)notification;
- @end
- //
- // Persistence2ViewController.m
- // Persistence2
- //
- // Created by liu lavy on 11-10-3.
- // Copyright 2011 __MyCompanyName__. All rights reserved.
- //
- #import "Persistence2ViewController.h"
- #import "Fourlines.h"
- @implementation Persistence2ViewController
- @synthesize field1;
- @synthesize field2;
- @synthesize field3;
- @synthesize field4;
- //数据文件的完整路径
- - (NSString *)dataFilePath {
- //检索Documents目录路径。第二个参数表示将搜索限制在我们的应用程序沙盒中
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- //每个应用程序只有一个Documents目录
- NSString *documentsDirectory = [paths objectAtIndex:0];
- //创建文件名
- return [documentsDirectory stringByAppendingPathComponent:kFilename];
- }
- //应用程序退出时,将数据保存到属性列表文件
- - (void)applicationWillResignActive:(NSNotification *)notification {
- Fourlines *fourlines = [[Fourlines alloc] init];
- fourlines.field1 = field1.text;
- fourlines.field2 = field2.text;
- fourlines.field3 = field3.text;
- fourlines.field4 = field4.text;
- NSMutableData *data = [[NSMutableData alloc] init];//用于存储编码的数据
- NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
- [archiver encodeObject:fourlines forKey:kDataKey];
- [archiver finishEncoding];
- [data writeToFile:[self dataFilePath] atomically:YES];
- [fourlines release];
- [archiver release];
- [data release];
- }
- /*
- // The designated initializer. Override to perform setup that is required before the view is loaded.
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- */
- /*
- // Implement loadView to create a view hierarchy programmatically, without using a nib.
- - (void)loadView {
- }
- */
- // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- - (void)viewDidLoad {
- [super viewDidLoad];
- NSString *filePath = [self dataFilePath];
- //检查数据文件是否存在
- if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
- //从文件获取用于解码的数据
- NSData *data = [[NSMutableData alloc] initWithContentsOfFile:[self dataFilePath]];
- NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
- Fourlines *fourlines = [unarchiver decodeObjectForKey:kDataKey];
- [unarchiver finishDecoding];
- field1.text = fourlines.field1;
- field2.text = fourlines.field2;
- field3.text = fourlines.field3;
- field4.text = fourlines.field4;
- [unarchiver release];
- [data release];
- }
- UIApplication *app = [UIApplication sharedApplication];
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(applicationWillResignActive:)
- name:UIApplicationWillResignActiveNotification
- object:app];
- [super viewDidLoad];
- }
- /*
- // Override to allow orientations other than the default portrait orientation.
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
- // Return YES for supported orientations
- return (interfaceOrientation == UIInterfaceOrientationPortrait);
- }
- */
- - (void)didReceiveMemoryWarning {
- // Releases the view if it doesn't have a superview.
- [super didReceiveMemoryWarning];
- // Release any cached data, images, etc that aren't in use.
- }
- - (void)viewDidUnload {
- self.field1 = nil;
- self.field2 = nil;
- self.field3 = nil;
- self.field4 = nil;
- [super viewDidUnload];
- }
- - (void)dealloc {
- [field1 release];
- [field2 release];
- [field3 release];
- [field4 release];
- [super dealloc];
- }
- @end
===================================================================================
===================================================================================
3、SQLite
- //
- // Persistence3ViewController.h
- // Persistence3
- //
- // Created by liu lavy on 11-10-3.
- // Copyright 2011 __MyCompanyName__. All rights reserved.
- //
- #import <UIKit/UIKit.h>
- #define kFilename @"data.sqlite3"
- @interface Persistence3ViewController : UIViewController {
- UITextField *filed1;
- UITextField *field2;
- UITextField *field3;
- UITextField *field4;
- }
- @property (nonatomic, retain) IBOutlet UITextField *field1;
- @property (nonatomic, retain) IBOutlet UITextField *field2;
- @property (nonatomic, retain) IBOutlet UITextField *field3;
- @property (nonatomic, retain) IBOutlet UITextField *field4;
- - (NSString *)dataFilePath;
- - (void)applicationWillResignActive:(NSNotification *)notification;
- @end
- //
- // Persistence3ViewController.m
- // Persistence3
- //
- // Created by liu lavy on 11-10-3.
- // Copyright 2011 __MyCompanyName__. All rights reserved.
- //
- #import "Persistence3ViewController.h"
- #import <sqlite3.h>
- @implementation Persistence3ViewController
- @synthesize field1;
- @synthesize field2;
- @synthesize field3;
- @synthesize field4;
- //数据文件的完整路径
- - (NSString *)dataFilePath {
- //检索Documents目录路径。第二个参数表示将搜索限制在我们的应用程序沙盒中
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- //每个应用程序只有一个Documents目录
- NSString *documentsDirectory = [paths objectAtIndex:0];
- //创建文件名
- return [documentsDirectory stringByAppendingPathComponent:kFilename];
- }
- //应用程序退出时,将数据保存到属性列表文件
- - (void)applicationWillResignActive:(NSNotification *)notification {
- sqlite3 *database;
- if(sqlite3_open([[self dataFilePath] UTF8String], &database) != SQLITE_OK) {
- sqlite3_close(database);
- NSAssert(0, @"Failed to open database");
- }
- for(int i = 1; i <= 4; i++) {
- NSString *fieldname = [[NSString alloc] initWithFormat:@"field%d", i];
- UITextField *field = [self valueForKey:fieldname];
- [fieldname release];
- char *update = "INSERT OR REPLACE INTO FIELDS (ROW, FIELD_DATA) VALUES (?, ?);";
- sqlite3_stmt *stmt;
- //将SQL语句编译为sqlite内部一个结构体(sqlite3_stmt),类似java JDBC的PreparedStatement预编译
- if (sqlite3_prepare_v2(database, update, -1, &stmt, nil) == SQLITE_OK) {
- //在bind参数的时候,参数列表的index从1开始,而取出数据的时候,列的index是从0开始
- sqlite3_bind_int(stmt, 1, i);
- sqlite3_bind_text(stmt, 2, [field.text UTF8String], -1, NULL);
- } else {
- NSAssert(0, @"Error:Failed to prepare statemen");
- }
- //执行SQL文,获取结果
- int result = sqlite3_step(stmt);
- if(result != SQLITE_DONE) {
- NSAssert1(0, @"Error updating table: %d", result);
- }
- //释放stmt占用的内存(sqlite3_prepare_v2()分配的)
- sqlite3_finalize(stmt);
- }
- sqlite3_close(database);
- }
- /*
- // The designated initializer. Override to perform setup that is required before the view is loaded.
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- */
- /*
- // Implement loadView to create a view hierarchy programmatically, without using a nib.
- - (void)loadView {
- }
- */
- // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- - (void)viewDidLoad {
- [super viewDidLoad];
- NSString *filePath = [self dataFilePath];
- //检查数据文件是否存在
- if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
- //打开数据库
- sqlite3 *database;
- if(sqlite3_open([filePath UTF8String], &database) != SQLITE_OK) {
- sqlite3_close(database);
- NSAssert(0, @"Failed to open database");
- }
- //创建表
- char *errorMsg;
- NSString *createSQL =
- @"CREATE TABLE IF NOT EXISTS FIELDS (ROW INTEGER PRIMARY KEY, FIELD_DATA TEXT);";
- if(sqlite3_exec(database, [createSQL UTF8String], NULL, NULL, &errorMsg) != SQLITE_OK) {
- sqlite3_close(database);
- NSAssert(0, @"Error creating table: %s", errorMsg);
- }
- //查询
- NSString *query = @"SELECT ROW, FIELD_DATA FROM FIELDS ORDER BY ROW";
- sqlite3_stmt *statement;
- //设置nByte可以加速操作
- if(sqlite3_prepare_v2(database, [query UTF8String], -1, &statement, nil) == SQLITE_OK) {
- while (sqlite3_step(statement) == SQLITE_ROW) {//返回每一行
- int row = sqlite3_column_int(statement, 0);
- char *rowData = (char *)sqlite3_column_text(statement, 1);
- NSString *fieldName = [[NSString alloc] initWithFormat:@"field%d", row];
- NSString *fieldValue = [[NSString alloc] initWithUTF8String:rowData];
- UITextField *field = [self valueForKey:fieldName];
- field.text = fieldValue;
- [fieldName release];
- [fieldValue release];
- }
- //释放statement占用的内存(sqlite3_prepare()分配的)
- sqlite3_finalize(statement);
- }
- sqlite3_close(database);
- }
- UIApplication *app = [UIApplication sharedApplication];
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(applicationWillResignActive:)
- name:UIApplicationWillResignActiveNotification
- object:app];
- [super viewDidLoad];
- }
- /*
- // Override to allow orientations other than the default portrait orientation.
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
- // Return YES for supported orientations
- return (interfaceOrientation == UIInterfaceOrientationPortrait);
- }
- */
- - (void)didReceiveMemoryWarning {
- // Releases the view if it doesn't have a superview.
- [super didReceiveMemoryWarning];
- // Release any cached data, images, etc that aren't in use.
- }
- - (void)viewDidUnload {
- self.field1 = nil;
- self.field2 = nil;
- self.field3 = nil;
- self.field4 = nil;
- [super viewDidUnload];
- }
- - (void)dealloc {
- [field1 release];
- [field2 release];
- [field3 release];
- [field4 release];
- [super dealloc];
- }
- @end
===================================================================================
===================================================================================
4、Core Data
- //
- // PersistenceViewController.h
- // Persistence4
- //
- // Created by liu lavy on 11-10-3.
- // Copyright 2011 __MyCompanyName__. All rights reserved.
- //
- #import <UIKit/UIKit.h>
- @interface PersistenceViewController : UIViewController {
- UITextField *filed1;
- UITextField *field2;
- UITextField *field3;
- UITextField *field4;
- }
- @property (nonatomic, retain) IBOutlet UITextField *field1;
- @property (nonatomic, retain) IBOutlet UITextField *field2;
- @property (nonatomic, retain) IBOutlet UITextField *field3;
- @property (nonatomic, retain) IBOutlet UITextField *field4;
- @end
- //
- // PersistenceViewController.m
- // Persistence4
- //
- // Created by liu lavy on 11-10-3.
- // Copyright 2011 __MyCompanyName__. All rights reserved.
- //
- #import "PersistenceViewController.h"
- #import "Persistence4AppDelegate.h"
- @implementation PersistenceViewController
- @synthesize field1;
- @synthesize field2;
- @synthesize field3;
- @synthesize field4;
- -(void) applicationWillResignActive:(NSNotification *)notification {
- Persistence4AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
- NSManagedObjectContext *context = [appDelegate managedObjectContext];
- NSError *error;
- for(int i = 1; i <= 4; i++) {
- NSString *fieldName = [NSString stringWithFormat:@"field%d", i];
- UITextField *theField = [self valueForKey:fieldName];
- //创建提取请求
- NSFetchRequest *request = [[NSFetchRequest alloc] init];
- //创建实体描述并关联到请求
- NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Line"
- inManagedObjectContext:context];
- [request setEntity:entityDescription];
- //设置检索数据的条件
- NSPredicate *pred = [NSPredicate predicateWithFormat:@"(lineNum = %d)", i];
- [request setPredicate:pred];
- NSManagedObject *theLine = nil;
- ////检查是否返回了标准匹配的对象,如果有则加载它,如果没有则创建一个新的托管对象来保存此字段的文本
- NSArray *objects = [context executeFetchRequest:request error:&error];
- if(!objects) {
- NSLog(@"There was an error");
- }
- //if(objects.count > 0) {
- // theLine = [objects objectAtIndex:0];
- //} else {
- //创建一个新的托管对象来保存此字段的文本
- theLine = [NSEntityDescription insertNewObjectForEntityForName:@"Line"
- inManagedObjectContext:context];
- [theLine setValue:[NSNumber numberWithInt:i] forKey:@"lineNum"];
- [theLine setValue:theField.text forKey:@"lineText"];
- //}
- [request release];
- }
- //通知上下文保存更改
- [context save:&error];
- }
- // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- /*
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization.
- }
- return self;
- }
- */
- // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- - (void)viewDidLoad {
- Persistence4AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
- NSManagedObjectContext *context = [appDelegate managedObjectContext];
- //创建一个实体描述
- NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Line" inManagedObjectContext:context];
- //创建一个请求,用于提取对象
- NSFetchRequest *request = [[NSFetchRequest alloc] init];
- [request setEntity:entityDescription];
- //检索对象
- NSError *error;
- NSArray *objects = [context executeFetchRequest:request error:&error];
- if(!objects) {
- NSLog(@"There was an error!");
- }
- for(NSManagedObject *obj in objects) {
- NSNumber *lineNum = [obj valueForKey:@"lineNum"];
- NSString *lineText = [obj valueForKey:@"lineText"];
- NSString *fieldName = [NSString stringWithFormat:@"field%d", [lineNum integerValue]];
- UITextField *textField = [self valueForKey:fieldName];
- textField.text = lineText;
- }
- [request release];
- UIApplication *app = [UIApplication sharedApplication];
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(applicationWillResignActive:)
- name:UIApplicationWillResignActiveNotification
- object:app];
- [super viewDidLoad];
- }
- /*
- // Override to allow orientations other than the default portrait orientation.
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
- // Return YES for supported orientations.
- return (interfaceOrientation == UIInterfaceOrientationPortrait);
- }
- */
- - (void)didReceiveMemoryWarning {
- // Releases the view if it doesn't have a superview.
- [super didReceiveMemoryWarning];
- // Release any cached data, images, etc. that aren't in use.
- }
- - (void)viewDidUnload {
- self.field1 = nil;
- self.field2 = nil;
- self.field3 = nil;
- self.field4 = nil;
- [super viewDidUnload];
- }
- - (void)dealloc {
- [field1 release];
- [field2 release];
- [field3 release];
- [field4 release];
- [super dealloc];
- }
- @end
5、AppSettings
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
===================================================================================
===================================================================================
6、普通文件存储
这种方式即自己将数据通过IO保存到文件,或从文件读取。
声明:此篇所有代码来自《Iphone4与IPad开发基础教程》
IOS 数据储存的更多相关文章
- iOS 数据储存--SQLite 操作数据库-FMDB,sqlite数据类型,保存图片,demo
1.SQLite 语句中 数据类型的储存 /* 不区分大小写 char(长度).字符串 NULL. 空值 INTEGER. 整型 REAL.浮点型 TEXT.文本类型 BLOB. 二进制类型,用来存储 ...
- iOS数据存储
[reference]http://www.infoq.com/cn/articles/data-storage-in-ios 谈到数据储存,首先要明确区分两个概念,数据结构和储存方式.所谓数据结构就 ...
- 面试题汇总--数据储存/应用程序/UI控件/客户端的安全性与框架处理。。。
一 数据储存 1.如果后期需要增加数据库中的字段怎么实现,如果不使用 CoreData 呢?编写 SQL 语句来操作原来表中的字段1)增加表字段ALTER TABLE 表名 ADD COLUMN 字 ...
- 关于JAVA数据储存
关于JAVA数据储存: 在JAVA中,有六个不同的地方可以存储数据: 1. 寄存器(register) 这是最快的存储区,因为它位于不同于其他存储区的地方--处理器内部.但是寄存器的数量极其有限,所以 ...
- Android下的数据储存方式(三)
Android下最好的数据储存方式:关系型数据库sqlite. 数据库的创建:使用SqliteOpenHelper类 结合SqliteOpenHelper类和SQLiteDatabase类的帮 ...
- Android下的数据储存方式( 二)
在上一篇文章中我们介绍了SharedPreferences的使用方法. 今天我们继续介绍另一种储存数据的方式:使用内部储存和外部储存 每一个Android设备都拥有两个数据储存区域:外部储存和外部储存 ...
- Android下的数据储存方式
安卓系统默认提供了一下几种数据储存的方式: Shared Preferences 内部储存 外部储存 SQLite数据库 保存到网络服务器 使用Shared Preferences ...
- iOS数据持久化-OC
沙盒详解 1.IOS沙盒机制 IOS应用程序只能在为该改程序创建的文件系统中读取文件,不可以去其它地方访问,此区域被成为沙盒,所以所有的非代码文件都要保存在此,例如图像,图标,声音,映像,属性列表,文 ...
- iOS 数据持久化(扩展知识:模糊背景效果和密码保护功能)
本篇随笔除了介绍 iOS 数据持久化知识之外,还贯穿了以下内容: (1)自定义 TableView,结合 block 从 ViewController 中分离出 View,轻 ViewControll ...
随机推荐
- vue-x和axios的学习
axios的使用 使用原因:因为vue本身就带有处理dom的功能,不希望再有其他操作dom的插件,所以用axios代替了jquery 功能:发送xhr请求 下载: $ npm install axio ...
- Excel—TIME函数简介与用法
问题场景 算员工饱和度时,需要从实际考勤打卡时间中减去午休时间1.5个小时: 导出的时间时分秒是分开的,连接时分秒. 场景一 计算员工饱和度,需要减去午休时间,用下班打卡时间减去午休的1.5小时算出的 ...
- AlexNet实现cifar10数据集分类
import tensorflow as tf import os from matplotlib import pyplot as plt import tensorflow.keras.datas ...
- [ASP.NET Core开发实战]基础篇03 中间件
什么是中间件 中间件是一种装配到应用管道,以处理请求和响应的组件.每个中间件: 选择是否将请求传递到管道中的下一个中间件. 可在管道中的下一个中间件前后执行. ASP.NET Core请求管道包含一系 ...
- mysql表中时间timestamp设计
Mysql数据库中CURRENT_TIMESTAMP和ON UPDATE CURRENT_TIMESTAMP区别 如图所示,mysql数据库中,当字段类型为timestamp时,如果默认值取CUR ...
- linux 下切换Python版本(某用户,共存,替换)
当你安装 Debian Linux 时,安装过程有可能同时为你提供多个可用的 Python 版本,因此系统中会存在多个 Python 的可执行二进制文件.你可以按照以下方法使用 ls 命令来查看你的系 ...
- python3笔记-列表
列表去重的两种方式: # 创建列表放数据 a =[1,2,1,4,2] b=[1,3,4,3,1,3] d=[] for i in a: if i not in d: d.append(i) prin ...
- 使用Vagrant 后发现虚拟机磁盘空间爆满的血泪填坑记
现象: 用了几天vagrant后,发现docker 里的 Mysql5.7 服务无法启动,用docker ps 命令,发现mysql一直在反复重启, 查看mysql log 发现说磁盘空间不够, ...
- MAC 上编译安装nginx-rtmp-module 流媒体服务器
MAC 上编译安装nginx-rtmp-module 流媒体服务器 记录踩坑过程 下载nginx和nginx-rtmp-module wget http://nginx.org/download/ng ...
- 会话技术之 Session
会话技术之 Session 不多废话,先来一个 HelloWorld. Session 有 get 肯定要先有 set . @Override protected void service(HttpS ...