gpt4 book ai didi

ios - 删除具有重复键的对象

转载 作者:行者123 更新时间:2023-11-30 11:14:59 25 4
gpt4 key购买 nike

我的代码...

class Inbox {

var user = "name"
var pmsg = "label"
var match = ""
var resim = "photo"
var userID = ""
var distance = ""
var updated = ""
var isAttendingNow = ""
var isAttendingNowText = ""


init(user : String, pmsg: String, match: String, resim: String, userID : String, distance: String, updated: String, isAttendingNow: String, isAttendingNowText: String) {

self.user = user
self.pmsg = pmsg
self.match = match
self.resim = resim
self.userID = userID
self.distance = distance
self.updated = updated
self.isAttendingNow = isAttendingNow
self.isAttendingNowText = isAttendingNowText

}


}

var arrayOfRels: [Inbox] = [Inbox]()

我的目标是删除 userID 键的重复项。

我怎样才能实现这一目标?

最佳答案

您可以使用一组来确定哪些 useID 是唯一的:

func filteredRels(source [Inbox]) -> [Inbox] {
var keys: Set<String> = []
return source.filter {
if keys.contains($0.userID) {
return false
} else {
keys.insert($0.userID)
return true
}
}
}

(在编辑器中被删除,因此可能需要一些小的清理。)

关于ios - 删除具有重复键的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51832136/

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