Ahsan Imtiaz Ahsan Imtiaz - 4 months ago 51
Swift Question

Swift Filter Nested Array

I have a

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 = ""

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)