Last active
May 18, 2024 16:16
-
-
Save edwellbrook/454c4b9f5649b68df08d542f3a27337c to your computer and use it in GitHub Desktop.
Create a UILocalizedIndexedCollation for a specific locale
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UILocalizedIndexedCollation { | |
static func collation(for locale: Locale) -> UILocalizedIndexedCollation? { | |
let collationPlistURL = Bundle(for: UILocalizedIndexedCollation.self).url( | |
forResource: "UITableViewLocalizedSectionIndex", | |
withExtension: "plist", | |
subdirectory: nil, | |
localization: locale.identifier | |
) | |
guard let collationPlistURL, let collationDict = try? NSDictionary(contentsOf: collationPlistURL, error: ()) else { | |
return nil | |
} | |
let collation = UILocalizedIndexedCollation.perform(Selector(("collationWithDictionary:")), with: collationDict).takeUnretainedValue() | |
return collation as? UILocalizedIndexedCollation | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment