开发者

CGMutablePathRef to NSMutableArray

开发者 https://www.devze.com 2023-01-24 07:59 出处:网络
How to add CGMutablePathRef to开发者_运维知识库 NSMutableArray?CGMutablePath path = <... your path ...>;

How to add CGMutablePathRef to开发者_运维知识库 NSMutableArray?


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.


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号