gpt4 book ai didi

ios - 从结构中删除重复项

转载 作者:行者123 更新时间:2023-11-29 05:39:00 26 4
gpt4 key购买 nike

我有一些结构

struct WheelBrand {
var id : String?
var name : String?

mutating func removeAll() {
self = WheelBrand()
}

我附加了它:

for (_,subJson):(String, JSON) in json["data"]{
let id = subJson["make_id"].stringValue
let name = subJson["make"].stringValue
self.itemWheelBrand.append(WheelBrand(id: id, name: name))
}

如何从我的结构中删除重复项,或者我必须为其附加唯一值?

最佳答案

完成添加到数组后,您可以通过这种方式进行过滤。

    var unique = [WheelBrand]()
for arrValue in itemWheelBrand {
if !unique.contains(where: { $0.id == arrValue.id }) {
unique.append(arrValue)
}
}

关于ios - 从结构中删除重复项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56755924/

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