gpt4 book ai didi

ios - 查找searBar.text是否包含整数字符串?

转载 作者:行者123 更新时间:2023-11-30 12:42:55 25 4
gpt4 key购买 nike

我正在尝试根据在搜索栏中输入的数字来更新我的搜索结果。但是,当我使用此代码时,它无法识别该号码

switch searchBar.text! {
case "", nil:
inSearchMode = false
case "\(Int)":
filteredData = dataSource.data.filter({"\($0.genusNum!)" == self.searchBar.text! })
default:
inSearchMode = true
filteredData = dataSource.data.filter({$0.identifier?.range(of: lower) != nil })
}

但是,当我将 Int 替换为实际整数时,它会起作用。问题是我需要它适用于我输入的任何整数,因为数字范围很大,我无法为每个单独的数字提供案例。

最佳答案

你可以这样获取int值

快速1

if let intValue = searchBar.text.toInt() where intValue > 0 {
// do your stuff
}

swift 2和3

if let intValue = Int(searchBar.text) {

if intValue > 0 {

}

}

希望这对你有帮助

关于ios - 查找searBar.text是否包含整数字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42033060/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com