CGMutablePathRef to NSMutableArray

后端 未结 2 1871
花落未央
花落未央 2021-01-26 15:32

How to add CGMutablePathRef to NSMutableArray?

2条回答
  •  广开言路
    2021-01-26 16:01

    You can wrap CGMutablePathRef to a NSValue and store it in array. Then when needed unwrap it:

    //Wrap
    NSValue *pathValue = [NSValue valueWithPointer: path];
    [array addObject:pathValue];
    
    //Unwrap
    NSValue *pathValue = [array objectAtIndex: index];
    CGMutablePathRef path = [pathValue pointerValue];
    

    Note that valueWithPointer: method does not affect object's retain count so you must not release your path when adding to array (release it later when it is not needed anymore)

提交回复
热议问题