开发者

Sorting of data

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
  NSEntityDescription *entity = [NSEntityDescription entityForName:entityName inManagedObjectContext:globalManagedObjectContext];
  [fetchRequest setEntity:entity];
   开发者_高级运维NSSortDescriptor *sortByName = [[NSSortDescriptor alloc] initWithKey:@"Name" ascending:YES];
  [fetchRequest setSortDescriptors:[NSArray arrayWithObject:sortByName]];
  fetchResults = [NSMutableArray arrayWithArray:[globalManagedObjectContext executeFetchRequest:fetchRequest error:nil]];
  [fetchRequest release];
  [sortByName release];
  return fetchResults;

follow case sensitiveness. Uppercase is on top.

Ab
Ba
a.

like above. Please give any solution for ignoring case


Use

NSSortDescriptor *sortByName = [[NSSortDescriptor alloc] initWithKey:@"Name" ascending:YES selector:@selector(caseInsensitiveCompare:)];


NSSortDescriptor *authorDescriptor = [[NSSortDescriptor alloc] initWithKey:@"author" ascending:YES];

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜