views:

325

answers:

1

I am trying to populate an OutlineView with the contents of a XML file.

I'd like to create and manage the values inside a NSIndexPath while cocoa parses the document. NSIndexPath has methods to add and remove indexes, but I need to increment/decrement the values in each index:

[0, 0]
[0, 1]
[0, 2]

and so on...

how can I do that?

+3  A: 

NSIndexPath isn't mutable, so you'll have to create a new index path every time. Probably the most efficient way would be to use length, getIndexes:, and initWithIndexes:length: messages, plus the realloc function to grow/shrink the buffer.

Don't forget to release the old index path after getting its indexes into the buffer and before allocking and initing (WithIndexes:length:) the new one, and to free the buffer when you're done. (Also don't forget that realloc frees the old buffer for you, so you only need to free the last buffer.)

Peter Hosey