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.
let nestedArray: [[User]] = [[user1, user2], [user3], [user4, user5]]
let searchName = "foo"
let filteredArray = nestedArray.map({
return $0.filter({ $0.name == searchName })
}).filter({ $0.count > 0 })
This is a purely functional way that results in a new nested array that only contains arrays with matching users and these arrays also will only contain the matching users.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With