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
0
votes
1 answer

Select NSTableView row programmatically and call method

I have an NSTableView that I add objects to (through core data). I came across this in my searches: NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:1]; [tableView selectRowIndexes:indexSet byExtendingSelection:NO]; which works, but the problem…
Matt S.
  • 13,305
  • 15
  • 73
  • 129
0
votes
2 answers

How to use IndexSet to find item in a custom Struct

I'm trying to use SwiftUI's .delete method on a list to identify what HKWorkout the user is trying to delete, but since I package my workouts into a custom WorkoutMonth object, I'm having difficulty figuring out how I can dig down into the specific…
GarySabo
  • 5,806
  • 5
  • 49
  • 124
0
votes
2 answers

sorted array from indexesOfObjectsPassingTest?

I have an array of myObjects called arrayToFilter. One (element?) of myObject is an array of bezierpaths. I am comparing the bezierpath at a particular index (thispath) to a second path, and making filteredArray composed of only those objects in…
Lordof Theflies
  • 301
  • 1
  • 6
  • 16
0
votes
0 answers

Objective-C NSIndexSet / NSArray - Selecting the "Best" Index from Set using Standard Dev

I have a question now about using standard deviation. And if I'm using it properly for my case as laid out below. The Indexes are all Unique here's a few questions I have about Standard Deviation: 1) Since I'm using all of the data should I be using…
0
votes
2 answers

why does __block not adding values to array

I am enumerating ranges inside a block and storing the values inside an array. I expected using __block should store the values inside block into array? __block NSMutableArray *array; [indexSet enumerateRangesUsingBlock:^(NSRange range,BOOL *…
humble_pie
  • 119
  • 10
0
votes
3 answers

Trying to access some elements in an IndexSet

I'm using IndexSet and I'm trying to access some indexes which at times are consecutive and at other times are not. For example, my set may contain [1, 2, 3, 5, 6, 7, 13, 31] I want to pull out of the set a range of 3...13, but am having difficulty…
user3284547
  • 105
  • 2
  • 11
0
votes
0 answers

NSTableView - Delete row in column

Is there a way to delete a row in a particular column, in NSTableView? If I use the following code: [self.newsList removeRowsAtIndexes:[NSIndexSet indexSetWithIndex:0] withAnimation:NSTableViewAnimationEffectNone]; All rows with index 0 are deleted…
0
votes
1 answer

NSIndexSet not set when user press enter after NSAlert

I have a very simple Mac app, that at one particular time, a button brings up a NSAlert with an input field. After that I take some actions on a NSTableView. It works fine if the user presses the OK button, but if the user presses ENTER, it does not…
Walucas
  • 2,549
  • 1
  • 21
  • 44
0
votes
1 answer

NSIndexSet indexPassingTest example

I can't seem to find a suitable example of how to use "indexPassingTest" with an NSIndexSet. I am trying to compare to NSIndexSets, in order to find the difference. I was hoping to use the following code: NSIndexSet *selectionIndexesNew = [change…
0
votes
1 answer

What can cause the error “Assertion failure in -[UICollectionViewData numberOfItemsBeforeSection:]”?

Here is my code snippet: NSIndexSet *indexSet = self.selectedIndexSet; __block SGPhotoSelectorCell *cell; [indexSet enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) { NSLog(@"%lu", (unsigned long)idx); ***NSIndexPath…
iAnchor
  • 1
  • 2
0
votes
1 answer

Sorted NSIndexSet of sub array of NSArray

Let say I have NSIndexSet of array indexes. I want to sort this NSIndexSet depends on NSArray. So, let say we have array : array = @[1,4,3,8,6,2,9]; and index set indexSet : (2,4,5,6) so "sub array" of this indexes would be subArray =…
Marko Zadravec
  • 8,298
  • 10
  • 55
  • 97
0
votes
1 answer

Objective C Logical OR operator not evaluating in block

I am trying to check which array element's values are equal to each other or to the NSNumber 10. The array has count 15. The problem is that when I test the value against NSNumber 10 in an if statement, the code does not seem to evaluate. In the…
noobsmcgoobs
  • 2,716
  • 5
  • 32
  • 52
0
votes
0 answers

Having trouble adding objects to the start of an array using an indexSet

I am downloading message objects from a Parse.com backend. I want to take this array of downloaded messages and insert them at the beginning of my local messages array. I am trying to use the code below: [receivedMessagesQuery…
Kex
  • 8,023
  • 9
  • 56
  • 129
0
votes
1 answer

NSMutableIndexSet to NSMutableArray

I have NSMutableIndexSet with indexes, and I want to create a NSArray with his indexes.. NSMutableIndexSet *mutableIndexSet = [NSMutableIndexSet new]; [mutableIndexSet addIndex:0]; [mutableIndexSet addIndex:2]; [mutableIndexSet addIndex:4]; how can…
benhi
  • 574
  • 1
  • 6
  • 24
0
votes
0 answers

NSManagedObjectContext deleteObject not working after app kill

My app is trying to download json data from the BE and save it to the core data. To keep track of the remaining data content to download, I save them in core data too. When the data is downloaded in batches of say 10, I would remove the downloaded…
Siddharthan Asokan
  • 4,321
  • 11
  • 44
  • 80