我打算使用以下代码行:
[[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES selector:@selector(caseInsensitiveCompare:)];
'caseInsensitiveCompare' 是我习惯在字符串上使用的方法。但是,示例显示我正在使用:
[[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
(不同之处在于本地化这个词)。这个词有什么作用——“本地化”方法与普通方法有何不同?
关于这两种方法的区别,Apple 开发者文档并没有提供太多信息。
最佳答案
这意味着比较器在比较时使用国家字符集。
例如,波兰语有字母 Ł,在国家字符集中,它位于 L 和 M 之间。
例如,当我们有字符串时:Ltest、Łtest、Mtest、Ztest 字符串:
caseInsensitiveCompare 给出结果:Ltest、Mtest、Ztest、Łtest
localizedCaseInsensitiveCompare 给出结果:Ltest, Łtest, Mtest, Ztest
关于iphone - localizedCaseInsensitiveCompare : and caseInsensitiveCompare:? 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8776781/