我正在使用subtracting
来获取工作正常的非常见元素。
但如果两个数组都有不同数量的元素(计数)
,则无效像
我有阵列
fileprivate var daysSelected:[Schedule.ScheduleDays] = [] {
didSet {
if let array = equipment.schedules?.map({$0.day}), Set(array).subtracting(Set(daysSelected)).count > 0{
debugPrint("After updated days ",array)
daySelectionChanged = true
} else {
daySelectionChanged = false
}
debugPrint("After updated days ",self.daysSelected)
}
}
enum ScheduleDays: String {
case everyday
case monday
case tuesday
case wednesday
case thursday
case friday
case saturday
case sunday
}
如果array
元素较少,则daysSelected
返回0
那么是否有任何解决办法从两个数组得到不同的元素,这个数组具有不同的计数而不检查array.count > daysSelected
实施例
假设daysSelected
有
- 0 : App.Schedule.ScheduleDays.tuesday
- 1 : App.Schedule.ScheduleDays.thursday
- 2 : App.Schedule.ScheduleDays.friday
- 3 : App.Schedule.ScheduleDays.saturday
- 4 : App.Schedule.ScheduleDays.sunday
- 5 : App.Schedule.ScheduleDays.wednesday
- 6 : App.Schedule.ScheduleDays.monday
和另一套有
- 0 : App.Schedule.ScheduleDays.friday
- 1 : App.Schedule.ScheduleDays.saturday
- 2 : App.Schedule.ScheduleDays.sunday
- 3 : App.Schedule.ScheduleDays.tuesday
- 4 : App.Schedule.ScheduleDays.wednesday
当我
Set(equipment.schedules!.map({$0.day})).subtracting(Set(daysSelected))
0 elements
和
po Set(daysSelected).subtracting(Set(equipment.schedules!.map({$0.day})))
▿ 2 elements
- 0 : App.Schedule.ScheduleDays.thursday
- 1 : App.Schedule.ScheduleDays.monday