一、Keys and Key Paths
Key
@interface Student : NSObject
@property (nonatomic, copy) NSString *name;
@property (nonatomic, assign) NSInteger *age;
@end
Student *student = [[Student alloc] init];
[student setValue:@"magic" forKey:@"name"];
Key Paths
@interface Teacher : NSObject
@property (nonatomic, strong) Student *stu;
@property (nonatomic, copy) NSString *name;
@end
Teacher *teacher = [[Teacher alloc] init];
teacher.stu = [[Student alloc] init];
[teacher setValue:@"magic" forKeyPath:@"stu.name"];
二、Collection Operators
本文主要介绍了Objective-C中的键值编码(KVC)和键值观察(KVO)机制,通过具体示例展示了如何使用KVC设置对象属性值以及如何利用KVO观察对象属性的变化。此外还涉及了集合操作符的应用。
1万+

被折叠的 条评论
为什么被折叠?



