訪問對象私有變量的方法有兩中 KVC 和 Runtime機制
今天主要說一下KVC吧,runtime有時間單獨寫一篇
廢話不多說,上代碼
Object.m文件
#import "Object.h"
@interface Object ()
@property (nonatomic, copy) NSString *string;
@end
@implementation Object
@end
訪問私有變量
Object *object = [[Object alloc] init];
[object setValue:@"123" forKey:@"string"];
NSLog(@"%@", [object valueForKey:@"string"]);