1.新建一个类
2.属性:
var name = ""
var age = ""
var gender = ""
3.在建一个类
4.protocol DealdDataProtocol {
func returnModelArray(arrayDict : [[String:String]]) ->[StudentModel]
}
class DeailData: NSObject ,DealdDataProtocol {
func returnModelArray(arrayDict: [[String : String]]) -> [StudentModel] {
var array : [StudentModel] = []
for dict in arrayDict {
let student = StudentModel()
student.name = dict["name"] ?? ""
student.age = dict["age"]!
student.gender = dict["gender"]!
array.append(student)
}
return array
}
}
let s = StudentModel()
let deal = DeailData()
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)
}
网友评论