swift - 如何在 Swift 中从 IndexSetB 中删除 IndexSetA?

标签 swift nsindexset

在 Objective-C 中,NSIndexSet 可以removeIndexes:(NSIndexSet *)indexSet:

[aIndexSet removeIndexes: bIndexSet];

有没有什么方法可以像 Objective-C 中的 NSIndexSet 那样在 Swift 中使用 IndexSet 来做到这一点?

最佳答案

有一个函数,来自documentation

mutating func subtract(_ other: IndexSet)

Removes the elements of the given set from this set.


var aIndexSet = IndexSet(integersIn: 0..<7)
let bIndexSet = IndexSet(integersIn: 4..<12)

aIndexSet.subtract(bIndexSet)

print(aIndexSet) // 0..<3

关于swift - 如何在 Swift 中从 IndexSetB 中删除 IndexSetA?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43953857/

相关文章:

objective-c - 在给定索引之前使用 enumerateObjectsAtIndexes 或 for 循环遍历 NSArray 的所有索引

ios - NSArray 的子数组的排序 NSIndexSet

ios - swift 锁匠 : fatal error: unexpectedly found nil while unwrapping an Optional value

ios - 私有(private)快速协议(protocol)是否可能?

swift - 半屏ios swift中的JSQMessagesViewController

swift - 自动布局无法正确处理 iPhone X 缺口

swift - 尝试访问 IndexSet 中的某些元素

Objective-C:如何将 NSIndexSet 转换为 NSIndexPath

swift - 为什么在 Swift 中使用元组而不是数组或字典?

cocoa - NSOutlineView 子类崩溃 - NSRangeException