//TZPerson是普通的继承自NSObject的类
TZPerson.h
#import <Foundation/Foundation.h>
@interface TZPerson : NSObject
@property (nonatomic, strong) NSString* name;
@property (nonatomic, assign) int age;
@property (nonatomic, strong) NSString* nick;
@property (nonatomic, assign) float height;
@end
TZPerson.m
@implementation TZPerson
// 赋值key值不存在
- (void) setValue:(id)value forUndefinedKey:(NSString *)key {
NSLog(@"key = %@值不存在 ", key);
}
@end
//在外部view中使用keyValue 来调用TZPerson的属性
ViewController.m
/// KVC字典操作
- (void) dictionaryTest {
TZPerson* p = [TZPerson new];
NSDictionary* dict = @{
@"name":@"Tom",
@"age":@18,
@"nick":@"Cat",
@"height":@180,
@"dd
iOS keyValue方法的使用
最新推荐文章于 2024-03-17 20:20:25 发布