Fedry Kemilau
Fedry Kemilau

Reputation: 692

How to sort NSString like iTunes sorting?

I want to sort array of NSString using iTunes sorting rules. This rule ignores leading articles such as "a, an, The". There are some other rules. Apple has posted an article about it. iTunes 7.3: Changes in music sort order

Anyone know any APIs in iOS 5.0 or later that can solve this?

Cheers, Fedry

Upvotes: 1

Views: 268

Answers (1)

TheAmateurProgrammer
TheAmateurProgrammer

Reputation: 9392

First of all, iterate through the NSString's and check if the first words are words you don't want using hasPrefix:, then you can replace them with stringByReplacingOccurrencesOfString:withString:

Then you can sort the string's like this:

sortedArray = [stringArray sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];

Or you can just create your own method for comparing between 2 strings instead of using localizedCaseInsensitiveCompare:

Upvotes: 1

Related Questions