-
let s = StudenModel()
let deal = DealData() var dictArray : [[String:String]] = [] for _ in 0..<5 { let dict = ["name":"Lily","age":"23","gender":"nv"] dictArray.append(dict) } let arrayModel = deal.returnModelArray(arrayDict: dictArray) for model in arrayModel { print(model.name) print(model.age) print(model.gender) } print(arrayModel) 2.
protocol DealDataProticol {
func returnModelArray(arrayDict : [[String:String]]) -> [StudenModel]
}
- func returnModelArray(arrayDict: [[String : String]]) -> [StudenModel] {
var array : [StudenModel] = []
for dict in arrayDict {
let stdent = StudenModel()
stdent.name = dict["name"] ?? ""
stdent.age = dict["age"]!
stdent.gender = dict["gender"]!
array.append(stdent)
}
return array
}
网友评论