标签:c语言 ios ios开发
CoreData:封装了Sqlite数据库的系统自带框架。
常用方法
@property(nonatomic,
strong)NSArray
*persons;
1、查询数据:
XYZAppDelegate * app = [UIApplication
sharedApplication].delegate;
NSFetchRequest *request = [[NSFetchRequest
alloc]initWithEntityName:@"Person"];
self.persons = [app.managedObjectContext
executeFetchRequest:request
error:nil];
(1)设置排序
NSSortDescriptor *sort = [NSSortDescriptor
sortDescriptorWithKey:@"name"
ascending:YES];
[request
setSortDescriptors:@[sort]];
sortDescriptorWithKey表示排序字段
(2)设置查询条件
NSPredicate *predicate = [NSPredicate
predicateWithFormat:@"name == ‘XYZ‘"];
[request
setPredicate:predicate];
2、插入数据
Person *person = [NSEntityDescription
insertNewObjectForEntityForName:@"Person"
inManagedObjectContext:app.managedObjectContext];
person.name =
self.nameText.text;
person.mobileNum =
self.MobileNumText.text;
[app
saveContext];
3、修改数据
self.person.name
= self.nameText.text;
self.person.mobileNum
= self.MobileNumText.text;
[app
saveContext];
4、删除数据
[app.managedObjectContext
deleteObject:self.persons[indexPath.row]];
[app
saveContext];
CoreData
标签:c语言 ios ios开发
原文地址:http://blog.csdn.net/debolee/article/details/44802547