我试图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