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」的 –