It seems like Swift 4 is implementing different method to (void)setValuesForKeysWithDictionary()
, what is appropriate replacement to this function in Swift 4?
I have struct of
struct User {
let name: String?
let email: String?
}
The dictionaryOfUsers
is coming from data structure which value are presented dynamically based on the number of users in the database:
let dictionaryOfUsers = [{key1: "name1", key2 : "[email protected]"}, {key1 : "name2", key2 : "[email protected]"} ]
let users = [User]
Now I want to use this function to create my user array to create dictionary in Swift 4:
for dictionary in dictionaryOfUsers {
let user = User()
user.setValuesForKeysWithDictionary(dictionary)
and append to users
users.append(user)
}
Try this method instead:
Your code has many minor issues — and some major issues as well (see matt answer for more info). Anyway, I think this should accomplish what you are after: