ios - ValueForKeyPath is not work how to fix it? -
animal class definition:
@property (nonatomic, strong) nsstring *food;
cat class definition:
@property (nonatomic, copy) nsstring *name; @property (nonatomic, copy) nsdata *birthday; @property (nonatomic, strong) animal *animal;
in main.m file:
[cat setvalue:@"fish" forkeypath:@"animal.food"]; nslog(@"cat eat: %@", [cat valueforkeypath:@"animal.food"]);
result:
2016-01-16 19:31:33.811 usage of kvc , kvo[6802:201576] cat eat: (null)
why null
?
thanks i've found problem.add following code can sovled. :)
[cat setvalue:[[animal alloc]init] forkeypath:@"animal"];
Comments
Post a Comment