How to use NSIndexSet

it would be the proper way: NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 3)]; or you can use the NSMutableIndexSet for the random indexes: NSMutableIndexSet *mutableIndexSet = [[NSMutableIndexSet alloc] init]; [mutableIndexSet addIndex:0]; [mutableIndexSet addIndex:2]; [mutableIndexSet addIndex:9]; etc.

Create NSIndexSet from integer array in Swift

Swift 3 IndexSet can be created directly from an array literal using init(arrayLiteral:), like so: let indices: IndexSet = [1, 2, 3] Original answer (Swift 2.2) Similar to pbasdf’s answer, but uses forEach(_:) let array = [1,2,3,4,5,7,8,10] let indexSet = NSMutableIndexSet() array.forEach(indexSet.add) //Swift 3 //Swift 2.2: array.forEach{indexSet.addIndex($0)} print(indexSet)