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

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -