我試圖alphabetize數組[字符串:任何]。我到目前爲止:Swift:Alphabetize List忽略「The」
func filterList() {
self.titleData.sort() {
item1, item2 in
let title1 = item1["title"] as! String
let title2 = item2["title"] as! String
return title1.localizedCaseInsensitiveCompare(title2) == ComparisonResult.orderedAscending
}
self.myCollectionTableView.reloadData()
}
它工作正常。但是,title1和title2是電影標題,所以我想在字母表中忽略「The」,但在TableView中返回完整的一個。我試過的所有東西(比如字符串中包含「The」的子字符串)只會讓我更困惑,任何幫助都會被讚賞!
寫上字符串的擴展,像'removingFirstThe',然後comaring之前調用兩個字符串。 – Alexander