我无法弄清楚如何让数组的一部分匹配整个数组,并且我想假装我们不知道usersInData [0,1,2,3]与verifiedUsers [0,1,2,3]相同,我想以某种方式匹配相同的值,而不使用每个数组的索引。数组中的某些字符串与另一个数组匹配
我想这 -
var usersInData = ["hello", "hello1", "hello2", "hello3", "hello4", "hello5", "hello6", "hello7"]
var verifiedUsers = ["hello", "hello1", "hello2", "hello3"]
if usersInData == verifiedUsers {
print("special user")
} else {
print("regular user")
}
但它打印“普通用户”,所以基本上没有工作。 我希望验证的用户与常规用户不同。因此,例如用户“你好”得到一个特殊的验证图标等。谢谢!
可能重复的https://stackoverflow.com/questions/39161168/how-to-compare-two-array-of-objects和https://stackoverflow.com/questions/36714522/how-do -i-check-in-swift-if-two-arrays-contain-the-same-elements-whatever-th- –
正如我从你的问题中可以理解的那样,你试图找出共同的价值。对?如果是,则从给定的两个数组创建两个集合并查找它们的交集。相交集将返回数组。例如let fruitsSet = Set(firstArray) let vegSet = Set(secondArray) let output = Array(fruitsSet.intersect(vegSet)) –