Wednesday 7 February 2018

Find the index of object in array in swift 4



userList is array of objects [User]
userID is identity of object, which is use for find index. 



let userID = "1"

 let tempIndex = userList.index(where: { (user: User) -> Bool in
            user.userID == userID

        })


tempIndex is position of object in userList array. 

You may access the object like bellow
let objUser = userList[tempIndex]



Happy coding! 



Bhavesh Kumbhani
IOS Software Professional 

follow on

No comments:

Post a Comment