.h
@interface LRPrivateModel : NSObject
@end
.m
#import “LRPrivateModel.h”
@interface LRPrivateModel ()
{
NSString *_privateStr;
}
@end
@implementation LRPrivateModel
- (instancetype)init {
self = [super init];
if (self) {
_privateStr = @“大栗子”;
}
return self;
}
@end
使用:
LRPrivateModel *model = [[LRPrivateModel alloc] init];
Ivar ivar = class_getInstanceVariable([LRPrivateModel class], “_privateStr”);
NSString *_age_value = object_getIvar(model, ivar);
NSLog(@"_privateStr_value:%@",_age_value);
结果:
_privateStr_value:大栗子