I am trying to implement the following behavior in an elegant way:
Replace userswith id in userIdsand filter out everything userwhose id is not inuserIds
Trying to do this "Swifty way":
var users = [["id": 3, "stuff": 2, "test": 3], ["id": 2, "stuff": 2, "test": 3], ["id": 1, "stuff": 2, "test": 3]]
var userIds = [1, 2, 3]
userIds.map({ userId in users[users.index(where: { $0["id"] == userId })!] })
gives the expected result for reordering and filtering. But the code falls when userIdscomprises an identifier that does not apply to userin users(for example 4) due to resiliency.
What am I missing to get it working smoothly?
source
share