How can an NSIndexSet be a root object?

98 views Asked by At

Here is a typical code snippet when reordering a table with drag and drop.

- (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard {
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:rowIndexes];
    [pboard declareTypes:[NSArray arrayWithObject:MyDataType] owner:self];
    [pboard setData:data forType:MyDataType];
    sourceIndex = [rowIndexes firstIndex];
    return YES;
}

Look at the line

 NSData *data = [NSKeyedArchiver archivedDataWithRootObject:rowIndexes];

How can rowIndexes be a root object?

The docs say that The NSIndexSet class represents an immutable collection of unique unsigned integers.... You use index sets in your code to store indexes into some other data structure. For example, given an NSArray object, you could use an index set to identify a subset of objects in that array.

It seems that the NSIndexSet is not a simply "an immutable collection of unique unsigned integers" but also a set of pointers that identify objects. It's very confusing, can anyone explain what's going on?

0

There are 0 answers