开发者

get the string used by localizedStandardCompare when it did a comparison

I'm sorting an array by using localizedStandardCompare:, which gives me the objects sorted in the correct, localized order. Now I want to use them in the index for a UITableView, which means I need to generate the section titles. Since localizedStandardCompare: localizes them, a string that starts with "Æ" is sorted with the A ob开发者_如何学运维jects.

So if I iterate the array and make a section for each first letter, I'll get sections "A", "Æ", "A", "B", etc. Is there a way to get the string that was used for comparison, or at least emulate it? I've tried converting with different encodings, but none will return me an "A" for "Æ".

Any other suggestions for how to generate the section titles for localized strings?


You can use the CFStringTransform method to get the used string.

For example use the kCFStringTransformToLatin value to get a simple latin string from the input string.

This won't actually behave exactly as the localizedStandardCompare: method, but you can use the string transform to generate an additional attribute for the object which you use for the actual sorting.

There are many good resources about this topic:

  • NSHipster about CFStringTransform
  • The Apple documentation about the function
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜