objective c - how to get _CAEAGLNativeWindow from iOS class "CAEAGLLayer" -
i tried opengl es native window (_win) class:
@interface caeagllayer : calayer <eagldrawable> { @private struct _caeaglnativewindow *_win; }
so extended category:
@interface caeagllayer(mylayer) - (void*) fetchwin; @end @implementation caeagllayer(mylayer) - (void*) fetchwin { homecoming self->_win; } @end
and utilize in class:
@implementation myclass - (void)setuplayer { _eagllayer = (caeagllayer*)self.layer; _eagllayer.opaque = yes; nslog(@"_eagllayer _win: %p", [_eagllayer fetchwin]); } @end
but when building, met link error:
undefined symbols architecture x86_64: "_objc_ivar_$_caeagllayer._win", referenced from: -[caeagllayer(mylayer) fetchwin] in openglview.o ld: symbol(s) not found architecture x86_64 clang: error: linker command failed exit code 1 (use -v see invocation)
the linker can't find symbol because, default, "ivar symbols @private
, @package
ivars are not exported." can't access _win
straight name in manner, if have header refers it.
however, can dive objc runtime , pull out instance variables. in case, might seek in -setuplayer
(after #importing <objc/objc-runtime.h>
):
ivar winivar = class_getinstancevariable([caeagllayer class], "_win"); void * winptr = (__bridge void *)object_getivar(_eagllayer, winivar);
(you may able utilize simple -valueforkey:
on layer using @"_win"
name of key, prefer runtime methods because read clearer you're trying do, circumvent intended abstraction.)
ios objective-c
No comments:
Post a Comment