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

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -