#import <Foundation/Foundation.h>

@interface myClass1 : NSObject
@property (nonatomic, copy) NSString *str;

@end

@implementation myClass1

@end


@interface myClass : NSObject
{
}
@property (nonatomic, retain) myClass1 *item;

@end

@implementation myClass

- (id)init{
    if(self = [super init]){
        [self setValue:[[myClass1 alloc]init] forKey:@"item"];//如果不给item设置值,则最后得到的item.str为空!
    }
    return self;
}
@end


int main(int argc, const char * argv[]) {
    @autoreleasepool {
        [class1 setValue:@"this is item.str" forKeyPath:@"item.str"];
        NSLog(@"item.str = %@",[class1 valueForKeyPath:@"item.str"]);
    }
    return 0;
}
 

 

高级用法:http://www.thinksaas.cn/group/topic/347021/

 

相关文章:

  • 2022-12-23
  • 2021-12-19
猜你喜欢
  • 2021-08-31
  • 2022-12-23
  • 2021-09-01
  • 2022-12-23
  • 2021-11-24
  • 2022-12-23
相关资源
相似解决方案