Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSIndexPath getIndexes method....how?

Am confused with the use of this method and the documentation that lists it as a (void) method.

"on return the index path's indexes"

where does it return anything too?

Should it not be:

- (NSIndexPath *)getIndexes:(NSUInteger *)indexes

getIndexes: Provides a reference to the index path’s indexes.

- (void)getIndexes:(NSUInteger *)indexes

Parameters indexes Pointer to an unsigned integer array. On return, the index path’s indexes. Availability Available in iOS 2.0 and later. Declared In NSIndexPath.h

like image 411
user7865437 Avatar asked May 29 '26 23:05

user7865437


2 Answers

You have to allocate the NSUInteger array of size [indexPath length] and pass it as argument. The return value will be written there. You have to release that array yourself or do nothing it was created on stack like this:

NSUInteger array[[indexPath length]];
[indexPath getIndexes: array];
like image 130
Max Avatar answered May 31 '26 11:05

Max


Maybe the next sentence explains the reason

It is the developer’s responsibility to allocate the memory for the C array.

It's actually a pointer to a C array that will be filled for you with the indexes, so there's no reason to additionally return it from the function - you already know its address.

You can use the function as follows

NSUInteger indexCount = [indices count];
NSUInteger buffer[indexCount];
[indices getIndexes:buffer maxCount:indexCount inIndexRange:nil];
like image 43
Tomas Vana Avatar answered May 31 '26 13:05

Tomas Vana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!