UISearchController 不识别元音变音,Swift,iOS
UISearchController does not recognise umlaut, Swift, iOS
我的应用程序中有搜索功能,但它无法识别任何变音符号 (ä,ö,ü)。我使用 UISearchController。如何调整它识别元音变音的代码?
([=12=].title as AnyObject).contains(self.searchController.searchBar.text!.lowercased())
这对我来说很好用。我会理智地检查你在 lldb 中的字符串。
func search() {
let stringWithDiaeresis = "Reënter"
let stringWithoutDiaeresis = "Reenter"
let searchStringWithDiaeresis = "Reë"
let searchStringWithoutDiaeresis = "Ree"
if stringWithDiaeresis.contains(searchStringWithDiaeresis) {
print("Range of Reë detected in Reënter")
}
if stringWithDiaeresis.contains(searchStringWithoutDiaeresis) {
print("Range of Reë detected in Reenter")
}
if stringWithoutDiaeresis.contains(searchStringWithDiaeresis) {
print("Range of Reë detected in Reenter")
}
if stringWithoutDiaeresis.contains(searchStringWithoutDiaeresis) {
print("Range of Ree detected in Reenter")
}
/* Prints the following:
Range of Reë detected in Reënter
Range of Ree detected in Reenter
*/
if (stringWithDiaeresis as AnyObject).contains(searchStringWithDiaeresis) {
print("Reënter contains Reë")
}
if (stringWithDiaeresis as AnyObject).contains(searchStringWithoutDiaeresis) {
print("Reënter contains Ree")
}
if (stringWithoutDiaeresis as AnyObject).contains(searchStringWithDiaeresis) {
print("Reenter contains Reë")
}
if (stringWithoutDiaeresis as AnyObject).contains(searchStringWithoutDiaeresis) {
print("Reenter contains Ree")
}
/* Prints the following:
Reënter contains Reë
Reenter contains Ree
*/
}
如果您的目的是将带变音符号的字符串与不带变音符号的字符串进行匹配,您将需要清理数据并从所有内容中删除变音符号。
例如
if stringWithDiaeresis.localizedStandardContains(searchStringWithoutDiaeresis) {
print("Reënter contains Ree")
}
/* Prints the following:
Reënter contains Ree
*/
这里的故事告诉我们,您确实应该使用 specialized/more 可用于字符串类型的复杂方法,而不是通用的 contains()。
我的应用程序中有搜索功能,但它无法识别任何变音符号 (ä,ö,ü)。我使用 UISearchController。如何调整它识别元音变音的代码?
([=12=].title as AnyObject).contains(self.searchController.searchBar.text!.lowercased())
这对我来说很好用。我会理智地检查你在 lldb 中的字符串。
func search() {
let stringWithDiaeresis = "Reënter"
let stringWithoutDiaeresis = "Reenter"
let searchStringWithDiaeresis = "Reë"
let searchStringWithoutDiaeresis = "Ree"
if stringWithDiaeresis.contains(searchStringWithDiaeresis) {
print("Range of Reë detected in Reënter")
}
if stringWithDiaeresis.contains(searchStringWithoutDiaeresis) {
print("Range of Reë detected in Reenter")
}
if stringWithoutDiaeresis.contains(searchStringWithDiaeresis) {
print("Range of Reë detected in Reenter")
}
if stringWithoutDiaeresis.contains(searchStringWithoutDiaeresis) {
print("Range of Ree detected in Reenter")
}
/* Prints the following:
Range of Reë detected in Reënter
Range of Ree detected in Reenter
*/
if (stringWithDiaeresis as AnyObject).contains(searchStringWithDiaeresis) {
print("Reënter contains Reë")
}
if (stringWithDiaeresis as AnyObject).contains(searchStringWithoutDiaeresis) {
print("Reënter contains Ree")
}
if (stringWithoutDiaeresis as AnyObject).contains(searchStringWithDiaeresis) {
print("Reenter contains Reë")
}
if (stringWithoutDiaeresis as AnyObject).contains(searchStringWithoutDiaeresis) {
print("Reenter contains Ree")
}
/* Prints the following:
Reënter contains Reë
Reenter contains Ree
*/
}
如果您的目的是将带变音符号的字符串与不带变音符号的字符串进行匹配,您将需要清理数据并从所有内容中删除变音符号。
例如
if stringWithDiaeresis.localizedStandardContains(searchStringWithoutDiaeresis) {
print("Reënter contains Ree")
}
/* Prints the following:
Reënter contains Ree
*/
这里的故事告诉我们,您确实应该使用 specialized/more 可用于字符串类型的复杂方法,而不是通用的 contains()。