Ahsan Imtiaz Ahsan Imtiaz - 2 months ago 23
Swift Question

Swift Filter Nested Array

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
}


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.

Answer
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")
        }
    }

}