我想在swift中搜索对象数组但我不知道如何:(
我试过了
filteredArrayUsingPredicate
Run Code Online (Sandbox Code Playgroud)
但仍然无法正常工作,它给了我一个错误信息
- 更新 -
错误信息是
swift:42:9: 'Array<search_options>' does not have a member named 'filteredArrayUsingPredicate'
Run Code Online (Sandbox Code Playgroud)
- 更新 -
class search_options {
let id:String
let option:String
init(){}
init(id:String ,option:String){
self.id = id
self.option = option
}
}
Run Code Online (Sandbox Code Playgroud)
我只想搜索选项变量
当我试图使用时
func searchBarSearchButtonClicked( searchBar: UISearchBar!)
{
let filteredArray = filter(search_options_array) { $0 == "test" }
println(searchBar.text)
}
Run Code Online (Sandbox Code Playgroud)
我收到了这条消息
swift:40:58: 'search_options' is not a subtype of 'String'
Run Code Online (Sandbox Code Playgroud)
flu*_*nic 11
查找特定对象的索引:
if let index = find(myArray, objectIAmLookingFor) {
// found! do something
}
Run Code Online (Sandbox Code Playgroud)
过滤器阵列:
let filteredArray = filter(myArray) { $0 == objectIAmLookingFor }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14382 次 |
| 最近记录: |