运行时 的用法
1、定义的一个类,里面有一个私有变量mt_,并且在初始化值为"HaHa Ha
"。@interface Mobj :
NSObject {@privateNSString *mt_;}
@end
@implementation
Mobj
- (id)init {self = [super init];
if (self) {mt_ =[[NSString alloc] initWithString:@"Ha Ha Ha"];}return self;}
- (void) dealloc {[mt_ release];
记得加头文件#import<objc/runtime.h):
NSString*str;Mobj *obj =[[Mobj alloc] init];
object_getInstanceVariable(obj, "mt_", (void*)&str);Ok,这样就实现了私有变量的访问