How do I create a mutable array of CGImageRefs?

后端 未结 3 1090
眼角桃花
眼角桃花 2020-12-21 01:21

I want to keep a mutable collection of CGImageRefs. Do I need to wrap them in NSValue, and if so how do I wrap and unwrap them properly? Can I get away with using a C array?

3条回答
  •  悲&欢浪女
    2020-12-21 02:02

    2011: just in case someone's still looking You can wrap CGImageRef in NSValues by using

    + (NSValue *)valueWithBytes:(const void *)value objCType:(const char *)type
    

    hence:

    CGImageRef cgImage = [self cgImageMethod];
    NSValue *cgImageValue = [NSValue valueWithBytes:&cgImage objCType:@encode(CGImageRef)];
    [array addObject:cgImageValue];
    

    to retrieve:

    CGImageRef retrievedCGImageRef;
    [[array objectAtIndex:0] getValue:&retrievedCGImageRef ];
    

    hope this helps somebody

提交回复
热议问题