1
我有我的排序爲數組如下:度假村斯威夫特陣列 - 空名稱將對象移至數組的末尾
contactsArray = unified.sorted{$0.name.localizedCaseInsensitiveCompare($1.name) == ComparisonResult.orderedAscending}
問題是我想用空字符串前""
反對移動到數組的末尾。在這裏尋找最有效的解決方案。
我有我的排序爲數組如下:度假村斯威夫特陣列 - 空名稱將對象移至數組的末尾
contactsArray = unified.sorted{$0.name.localizedCaseInsensitiveCompare($1.name) == ComparisonResult.orderedAscending}
問題是我想用空字符串前""
反對移動到數組的末尾。在這裏尋找最有效的解決方案。
試試這個:
contactsArray = unified.sorted { (a, b) -> Bool in
if a.name.isEmpty {
return false
} else if b.name.isEmpty {
return true
} else {
return a.name.localizedCaseInsensitiveCompare(b.name) == .orderedAscending
}
}