Incremental NSIndexPath Values

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

I would like to create and manage values ​​inside NSIndexPath, and cocoa parses the document. NSIndexPath has methods for adding and removing indexes, but I need to increase / decrease the values ​​in each index:

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

etc.

How can i do this?

+3
source share
2 answers

NSIndexPath does not change, so you have to create a new index path every time. Probably the most efficient way would be to use messages length, getIndexes:and initWithIndexes:length:, as well as a function reallocto increase / compress the buffer.

release alloc king init ing (WithIndexes:length:) , free - , . ( , realloc , free .)

+5

@LolaRun - Cocoa , , realloc. , - :

NSUInteger newIndexes[] = {0,1};
NSUInteger len = sizeof(newIndexes)/sizeof(NSUInteger); //sorry!
NSIndexPath *baseIndexPath = [NSIndexPath indexPathWithIndexes:newIndexes 
                                                        length:len];
NSUInteger i;
for (i=0; i<10; i++) {
    NSIndexPath *newIndexPath = [baseIndexPath indexPathByAddingIndex:i];
    NSLog(@"newIndexPath = %@", newIndexPath);
}

indexPath ( indexPath newIndexes ):

NSIndexPath *someIndexPath = [NSIndexPath indexPathWithIndexes:newIndexes 
                                                        length:len];
    NSUInteger newIndexes2[[someIndexPath length]];
    [someIndexPath getIndexes:newIndexes2];

    NSUInteger len2 = sizeof(newIndexes2)/sizeof(NSUInteger);
    NSIndexPath *baseIndexPath2 = [NSIndexPath indexPathWithIndexes:newIndexes2 
                                                             length:len2];
    NSUInteger ii;
    NSInteger start = [someIndexPath indexAtPosition:[someIndexPath length] -1];
    for (ii=start; ii<10; ii++) {
        NSIndexPath *newIndexPath2 = [baseIndexPath2 indexPathByAddingIndex:ii];
        NSLog(@"newIndexPath2 = %@", newIndexPath2);
    }

, 0.1, - . Mix 'n, .

0

Source: https://habr.com/ru/post/1716060/


All Articles