这是klass1;
class Klass1 {
let name:[String]
let number:[Double]
init(name: [String], number: [Double]) {
self.name = name
self.number = number
}
}
课程结束
var data1 = [Klass1]()
let xxx = ["name1","name2","name3"]
let yyy = [1,2,3]
setupKlass1(){
data1.append(Klass1(name: xxx, number: yyy))
}
我想从data1中获取所有数据(每个名称和数字值),并将其作为Klass2追加到data2中
下面是Klass2;
class Klass2 {
let name:String
let number:Double
init(name: String, number: Double) {
self.name = name
self.number = number
}
}
end of class
var data2 = [Klass2]()
答案 0 :(得分:3)
我想你想得到这样的东西
var data2: [Klass2] = data1.flatMap {
zip($0.name, $0.number).map {
Klass2(name: $0, number: $1)
}
}