Stanley
Stanley

Reputation: 4486

Changing the value of a NSIndexPath object

If I have an index path with value : { 0, 0}. What is the proper way to change it to { 0, 1} ? I know if it were an ordinary c array it would just be :

unsigned i_array[] = { 0, 0};
i_array[1] = 1;

But from NSIndexPath's documentation, the closest I can get is with :

– indexPathByRemovingLastIndex
– indexPathByAddingIndex:

It seems a bit cumbersome. Is there a way that I can just overwrite the last member of the index array ?

Upvotes: 3

Views: 3960

Answers (2)

PedroFeu
PedroFeu

Reputation: 1

indexPath = [NSIndexPath indexPathForRow:0 inSection:1];

Upvotes: 0

akashivskyy
akashivskyy

Reputation: 45210

NSIndexPath is not an array. It's an object with 2 readonly properties: row and section. You can't change them, however, you can create a new indexPath based on the old one:

NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:oldIndexPath.row inSection:1];
oldIndexPath = newIndexPath;

Upvotes: 12

Related Questions