ios - Swift:对象数组搜索

标签 ios arrays swift

我想快速搜索对象数组 但我不知道如何:(

我试过了

filteredArrayUsingPredicate

还是不行,报错

-- 更新--

错误信息是

swift:42:9: 'Array<search_options>' does not have a member named 'filteredArrayUsingPredicate'

-- 更新--

class search_options {
        let id:String
        let option:String

        init(){}

        init(id:String ,option:String){
            self.id = id
            self.option = option
        }
    }

我只想在选项变量中搜索

当我尝试使用

func searchBarSearchButtonClicked( searchBar: UISearchBar!)
{
    let filteredArray = filter(search_options_array) { $0 == "test" }
    println(searchBar.text)
}

我收到了这条消息

swift:40:58: 'search_options' is not a subtype of 'String'

最佳答案

查找特定对象的索引:

if let index = find(myArray, objectIAmLookingFor) {
    // found! do something
}

过滤数组:

let filteredArray = filter(myArray) { $0 == objectIAmLookingFor }

关于ios - Swift:对象数组搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26135130/

相关文章:

swift 3(SpriteKit): Making a projectile move

swift - 在 SwiftUI 中强制 View 位于 View 的右下角

ios - iOS设备未收到CloudKit通知

ruby - 在 Ruby 中测试重叠数组

arrays - 将附加数组保存到 NSUserdefaults 不返回附加数组

java - 如何使用变量来指定数组长度?

javascript - 编写 Array.every() 函数

iPhone MPMoviePlayerController : download files while streaming en play them locally

iphone - UITableViewCell 不显示全文

ios - UIView 动画不起作用