@interface DVITeacher : NSObject { NSString *_name; NSInteger age; } @end DVITeacher *teacher = [[DVITeacher alloc] init]; [teacher setValue: @"Zhangsan" forKey:@"name"]; NSString *name = [teacher valueForKey:@"name"]; @interface DVIClass : NSObject { DVIPerson *_teacher; NSArray *_allTeachers; } @end DVIClass *myClass = [[DVIClass alloc] init]; [myClass setValue: @"Lisi" forKeyPath: @"teacher.name"]; NSString *name = [myClass valueForKeyPath:@"teacher.name"]; NSArray *array = [NSArray arrayWithObjects:teacher]; [myClass setValue: array forKeyPath:@"allTeachers"]; NSArray *teachers = [myClass valueForKeyPath:@"allTeachers.name"];