如何使 UITextField 中的文本全部小写?

How can I make text in UITextField all lowercase?

我对搜索用户名的 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

但这仍然允许用户输入大写字母。

我只想将文本转换为小写 (searchField.text.lowercased()) 并允许用户输入大写字母。这将阻止用户在尝试键入大写字母时感到沮丧。