本文介绍了iOS:自然排序顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个使用Core Data保存和检索数据的iOS应用程序。 我如何以自然排序顺序提取按NSString类型字段排序的数据?
I have an app for iOS that uses Core Data to save and retrieve data. How would I fetch data sorted by a field of NSString type in natural sort order?
现在结果是:
100_title 10_title 1_title我需要:
1_title 10_title 100_title推荐答案
您可以使用 localizedStandardCompare:作为Core Data fetch请求的排序描述符中的选择器,例如
You can use localizedStandardCompare: as selector in the sort descriptor for the Core Data fetch request, for example
NSSortDescriptor *titleSort = [[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES selector:@selector(localizedStandardCompare:)]; [fetchRequest setSortDescriptors:[titleSort]];更多推荐
iOS:自然排序顺序
发布评论