gpt4 book ai didi

arrays - Swift 乘法数组索引

转载 作者:行者123 更新时间:2023-11-28 10:37:20 26 4
gpt4 key购买 nike

这里是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]()

最佳答案

我想你会喜欢这样的东西

var data2: [Klass2] = data1.flatMap {
zip($0.name, $0.number).map {
Klass2(name: $0, number: $1)
}
}

关于arrays - Swift 乘法数组索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52731894/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com