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

STW
  • 44,917
  • 17
  • 105
  • 161
Duck
  • 34,902
  • 47
  • 248
  • 470

1 Answers1

6

This should work:

CGLayerRef giveMeBackTheLayer;
[myCopy getValue:&giveMeBackTheLayer];
  • just a bit off topic... do you know how can I discover the number of bytes myCopy is using?... thanks. – Duck Jun 02 '11 at 02:05
  • @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. –  Jun 02 '11 at 02:10
  • You'd need to store that information separately. You can't get it from the `NSValue`. – Rob Keniger Jun 02 '11 at 02:10
  • @Bavarious - the number of bytes needed to store CGLayerRef – Duck Jun 02 '11 at 02:25
  • @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. –  Jun 02 '11 at 02:27