Swift 4似乎正在实施不同的方法到(void)setValuesForKeysWithDictionary()
,Swift 4中这个函数有什么合适的替代?setValuesForKeysWithDictionary in Swift 4?
我有
struct User {
let name: String?
let email: String?
}
的dictionaryOfUsers
结构是从哪个值都动态地根据用户的数据库数量的数据结构来:
let dictionaryOfUsers = [{key1: "name1", key2 : "[email protected]"}, {key1 : "name2", key2 : "[email protected]"} ]
let users = [User]
现在我想用这个函数来创建我的用户数组以在Swift 4中创建字典:
for dictionary in dictionaryOfUsers {
let user = User()
user.setValuesForKeysWithDictionary(dictionary)
并追加到用户
users.append(user)
}
'key1'和'key2'代表什么?我期望''name''和'''email''字符串代替... –
是key1和key2是用于“name”和“email”的 –