Wednesday 7 February 2018

Filter array of objects in swift 4


userList is array of objects [User]
userID is identity of object, which is use for filter 

See bellow method, In this method filtered the userList array by userID. get all users which are having same userID.



func filtered(userID: String) -> [User] {
        if userList.count > 0{
            let filteredArray = userList.filter { (obj) -> Bool in
                obj.userID == userID
            }
            return filteredArray
        }
        return []
    }
 







Happy coding! 



Bhavesh Kumbhani
IOS Software Professional 

follow on

No comments:

Post a Comment