CGMutablePathRef to NSMutableArray

后端 未结 2 451
没有蜡笔的小新
没有蜡笔的小新 2021-01-26 15:35

How to add CGMutablePathRef to NSMutableArray?

相关标签:
2条回答
  • 2021-01-26 15:50
    CGMutablePath path = <... your path ...>;
    [mutableArray addObject:(id)path];
    

    CGPath and CGMutablePath are just opaque CFType object types, and those can be added (via casting to id) to any Cocoa container classes that are toll-free bridged to their CoreFoundation counter-parts.

    0 讨论(0)
  • 2021-01-26 16:00

    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)

    0 讨论(0)
提交回复
热议问题