我在firebase中有以下查询,用于搜索用户名。
let ref = Database.database().reference().child("UsernameIndex")
ref.queryOrdered(byChild: "username").queryStarting(atValue: username).queryEnding(atValue: username+"\u{f8ff}").observeSingleEvent(of: .value) { snap in
问题在于,如果我在任何时候键入大写字母,都不会搜索,那么我如何才能使所有字母大小写或使文本小写或使查询不区分大小写?
使文本变为小写的最佳方法是:
searchField.autocapitalizationType = .none
searchField.autocorrectionType = .no
searchField.spellCheckingType = .no
但是,这仍然允许用户键入大写字母。
答案 0 :(得分:2)
我只需要将文本转换为小写(searchField.text.lowercased()
)并允许用户键入大写字母即可。这样可以避免用户在尝试输入大写字母时感到沮丧。