NSArray to C array

后端 未结 3 390
谎友^
谎友^ 2020-12-05 08:14

can we convert NSArray to c array. if not what alternatives are there.[suppose i need to feed the c array in opengl functions where the c array contains vertex pointer read

3条回答
  •  庸人自扰
    2020-12-05 08:36

    NSArray has a -getObjects:range: method for creating a C-array for a subrange of an array.

    Example:

    NSArray *someArray = /* .... */;
    NSRange copyRange = NSMakeRange(0, [someArray count]);
    id *cArray = malloc(sizeof(id *) * copyRange.length);
    
    [someArray getObjects:cArray range:copyRange];
    
    /* use cArray somewhere */
    
    free(cArray);
    

提交回复
热议问题