iPhone - encoding and decoding a NSValue
Asked Answered
C

1

6

So I read here on SO that I can encode a CGLayerRef to a NSValue using

NSValue *myCopy = [[NSValue alloc] initWithBytes:&myLayer objCType:@encode(CGLayerRef)]; 

but how do I recreate the CGLayerRef from myCopy?

thanks

Castora answered 2/6, 2011 at 0:59 Comment(0)
P
6

This should work:

CGLayerRef giveMeBackTheLayer;
[myCopy getValue:&giveMeBackTheLayer];
Pule answered 2/6, 2011 at 1:11 Comment(5)
just a bit off topic... do you know how can I discover the number of bytes myCopy is using?... thanks.Castora
@Digital The number of bytes in the whole instance or the number of bytes needed to store a CGLayerRef? It’s probably a combination of class_getInstanceSize() and sizeof CGLayerRef. The actual layer struct is opaque, though.Pule
You'd need to store that information separately. You can't get it from the NSValue.April
@Bavarious - the number of bytes needed to store CGLayerRefCastora
@Digi sizeof CGLayerRef, then. Note that CGLayerRef is a pointer, so it has the same size as any other pointer in your target platform: 32 bits.Pule

© 2022 - 2024 — McMap. All rights reserved.