Questions tagged [nsindexset]

The NSIndexSet class represents an immutable collection of unique unsigned integers, known as indexes because of the way they are used. This collection is referred to as an index set. 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.

NSIndexSet is a Foundation Framework collection class that is similar to NSRange, with the notable exception of being able to support non-contiguous series. An NSIndexSet can be created from a range using the indexSetWithIndexesInRange: class constructor:

NSIndexSet expresses a collection of unique whole numbers; its purpose is to express element numbers of an ordered collection, such as an NSArray. It is available in iOS 2.0 and later, available in OS X v10.3 and later . An NSIndexSet is immutable; its mutable subclass is NSMutableIndexSet. You can form a simple NSIndexSet consisting of just one contiguous range directly, by passing an NSRange to indexSetWithIndexesInRange: but to form a more complex index set you’ll need to use NSMutableIndexSet so that you can append additional ranges.

Example :

    NSRange range = NSMakeRange(0, 10);
    NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:range];

Related Source:

57 questions
2
votes
1 answer

NSIndexSet.enumerateIndexesUsingBlock using Swift Closure

I'm writing a method to copy data from a table view to the paste board but if any rows are selected it should specifically only copy the data from the selected rows so I need to iterate over the index set ... func…
BadmintonCat
  • 9,416
  • 14
  • 78
  • 129
2
votes
2 answers

In ios tableview, why section is a NSIndexSet?

I am newbie to iOS development so this question is quite silly, but I do have a hard time figuring out how the following code works: -(void)controller:(NSFetchedResultsController *)controller…
cosmo
  • 27
  • 3
2
votes
1 answer

Deleting UITableView sections combined with custom section headers UIViews = bug in Apple's code?

I'm trying to delete a section from a UITableView using animation and custom table section header UIViews. I use... //Deletion from my model done here (not shown) and then perform the deleteSections... [self.tableView beginUpdates]; [self.tableView…
Cal
  • 1,625
  • 4
  • 20
  • 30
1
vote
1 answer

SwiftUI, Core Data - Delete List Item with Context Menu

I'm trying to delete a list item with context menu. The data is fetched from Core Data. .onDelete works as expected with my deleteExercise func without further do. But when calling the deleteExercise within the context menu button, it asks for the…
wildcard
  • 896
  • 6
  • 16
1
vote
2 answers

How to indicate index of NSIndexSet object?

everyone. I want to indicate index of NSIndexSet object. Find various method but I can't find. How to indicate index of NSIndexSet object? NSMutableArray *array = [[NSMutableArray alloc]initWithObjects:@"A",@"B",@"C",@"A", nil]; NSIndexSet…
S.J. Lim
  • 3,095
  • 3
  • 37
  • 55
1
vote
1 answer

How to access the array position using SwiftUI's onDelete() function

I am attempting to sync the UI delete with deleting a record from CloudKit. SwiftUI has the onDelete() function that you can add to a List view which gives you the swipe to delete gesture. I am trying to use this to access the position in the array…
nix.codes
  • 388
  • 2
  • 20
1
vote
1 answer

How to remove IndexSetA from IndexSetB in Swift?

In Objective-C, the NSIndexSet can removeIndexes:(NSIndexSet *)indexSet: [aIndexSet removeIndexes: bIndexSet]; Is there some way to do this with IndexSet in Swift like the NSIndexSet in Objective-C?
a_tuo
  • 651
  • 7
  • 23
1
vote
2 answers

Random index from NSIndexSet

I need to pick a random index from those included in an NSIndexSet. For reference, NSSet defines the -anyObject method (documentation) for picking arbitrary objects from a set. Is there a similar functionality in NSIndexSet? (It turns out -anyObject…
insys
  • 1,288
  • 13
  • 26
1
vote
1 answer

How to correctly use short Swift closures in calls to ObjC classes

I want to use short form of closure {$0 > 1} in calls to NSIndexSet class: let indexSet: NSIndexSet = getSomeIndexSet() let filteredIndexSet = indexSet.indexesPassingTest(){$0 > 1} but it gives me Cannot invoke 'indexesPassingTest' with an…
1
vote
1 answer

Crash in NSOutlineView subclass - NSRangeException

I have a subclass for NSOutlineView which listens to NSManagedObjectContext change notifications and updates the outlineView accordingly. I'm getting a strange crash at some point that my users are reporting (that I can't reproduce on my own) ...…
Z S
  • 7,039
  • 12
  • 53
  • 105
1
vote
0 answers

Get array of index from an NSIndexSet?

To call UICollectionView's deleteItemsAtIndexPaths I need array of indexPaths. But I have them in an NSIndexSet. Any elegant way to retrieve it, not by looping?
János
  • 32,867
  • 38
  • 193
  • 353
1
vote
2 answers

How to know if a row in a UITableView has been selected?

I am using Apple's MultiSelectTableView as a way to learn about NSIndexSet. I can easily create selected items and read them back in the debugger. I've tried several methods to "read" the set when the app runs again, but I can't figure this out. So,…
ICL1901
  • 7,632
  • 14
  • 90
  • 138
1
vote
3 answers

How can I select elements from an NSArray according to array of NSIndexPaths

Is there a fast way to get all elements at indexes from an array returned from a UITableView (NSArray of NSIndexPaths). For instance: [self.dataSourceArray selectItemsAt:[self.tableView indexPathsForSelectedItems]]
Avba
  • 14,822
  • 20
  • 92
  • 192
1
vote
3 answers

removeObjectsAtIndexes causing a crash

Can't figure out whats causing the crash here. Im enumerating over a NSMutableArray and placing the indexes of certain objects into a mutable index set, then attempting to remove the corresponding objects from the array. here is my code …
Sean Danzeiser
  • 9,141
  • 12
  • 52
  • 90
1
vote
2 answers

Search index of NSMutableArray

I need to search the index of a string from NSMutableArray. I have implemented the code & which works perfect, but I need to increase the searching speed than this. I have used the following code: NSIndexSet *indexes = [mArrayTableData…
Fevicks
  • 223
  • 1
  • 10