Skip to content

Instantly share code, notes, and snippets.

@edwellbrook
Last active May 18, 2024 16:16
Show Gist options
  • Save edwellbrook/454c4b9f5649b68df08d542f3a27337c to your computer and use it in GitHub Desktop.
Save edwellbrook/454c4b9f5649b68df08d542f3a27337c to your computer and use it in GitHub Desktop.
Create a UILocalizedIndexedCollation for a specific locale
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