码迷,mamicode.com
首页 > 其他好文 > 详细

CoreData简单教学(二)

时间:2014-10-04 23:01:17      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   io   ar   for   sp   div   

1.CoreData 编写方便, 管理方便, 出错不易寻找, 整体性强, 关联性强

2.简单介绍查询的办法

 

 1 #pragma mark - 
 2 - (NSMutableArray *) findAll {
 3     NSManagedObjectContext * cxt = [self managedObjectContext];
 4     
 5     NSEntityDescription * entityDescription = [NSEntityDescription entityForName:@"Person" inManagedObjectContext:cxt];
 6     NSFetchRequest * request = [[NSFetchRequest alloc] init];
 7     [request setEntity:entityDescription];
 8     
 9     NSSortDescriptor * sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
10     [request setSortDescriptors:@[sortDescriptor]];
11     
12     NSError * error = nil;
13     NSArray * listData = [cxt executeFetchRequest:request error:&error];
14     NSMutableArray * resListArray = [[NSMutableArray alloc] init];
15     
16     for (Person * handle in listData) {
17         Person * person = [[Person alloc] init];
18         person.name = handle.name;
19         person.age = handle.age;
20         
21         [resListArray addObject:person];
22     }
23     
24     return resListArray;
25 }

 

CoreData简单教学(二)

标签:des   style   blog   color   io   ar   for   sp   div   

原文地址:http://www.cnblogs.com/Dylan-Alice/p/Dy_CoreData_1.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!