iOS:自然排序顺序

编程入门 行业动态 更新时间:2024-10-22 10:42:59
本文介绍了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:自然排序顺序

本文发布于:2023-10-14 22:02:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492341.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:顺序   自然   iOS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!