Swift过滤器嵌套数组 [英] Swift Filter Nested Array

查看:72
本文介绍了Swift过滤器嵌套数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 NSMutableArray ,它本身内部有许多数组.在每个索引的每个数组内部,它们还具有以下给定类的自定义对象.

I have a NSMutableArray which it self has many arrays inside it. Inside each array at all index they further had custom objects of class given bellow.

Class User:NSObject{
    var name = ""
    var userName = ""
    var email = ""
    var age = 0
    var gender = ""
    var 
}

我想针对两个对象过滤此嵌套数组.例如,如果用户在searchBar中键入一些文本,并检查该嵌套数组中的该文本是否与名称或userName或两者匹配.

I want to filter this nested array with respect to two objects. For example if user type some text in searchBar and check that text in that nested array if that text matches with the name or the userName or both.

推荐答案

let textToSearch:String = "some text"

for nestedArray in myArray {

    for item:User in nestedArray
    {
        if user.name.contains(textToSearch) || user.userName.contains(textToSearch)
        {
            print("found")
        }
    }

}

这篇关于Swift过滤器嵌套数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆