美文网首页
swift 如何set去重

swift 如何set去重

作者: 可乐小子 | 来源:发表于2024-04-09 15:50 被阅读0次

    let dataArr = self.withdrowArray.flatMap({$0.items }) + array
    var setData = Set<String>()
    var nowArr = SectionData

                    for model in dataArr {
                        //去重,去除重复月份
                        if !setData.contains(model.showTime) {
                            setData.insert(model.showTime)
                            
                            var modelArr = [CR_WithdrawModel]()
                            if let items = nowArr.first(where: { $0.time == model.showTime })?.items {
                                modelArr = items
                            }
                            modelArr.append(model)
                            nowArr.append(SectionData(time: model.showTime, items: modelArr))
                        } else {
                            if let section = nowArr.firstIndex(where: { $0.time == model.showTime }) {
                                var items = nowArr[section].items
                                items.append(model)
                                nowArr[section].items = items
                            } else {                            nowArr.append(SectionData(time: model.showTime, items: [model]))
                            }
                        }
                    }
                    self.withdrowArray = nowArr

    相关文章

      网友评论

          本文标题:swift 如何set去重

          本文链接:https://www.haomeiwen.com/subject/ytufxjtx.html