Why does the following objective-c code print
name : (null)
but if the NSLog(@”Country name : %@”, c.name); is uncommented then it prints:
Country name : USA
name : USA
Country *c = row;
//NSLog(@"Country name : %@", c.name);
Ivar ivar = class_getInstanceVariable([row class], "name");
NSString *name = object_getIvar(row, ivar);
NSLog(@"name : %@", name);
I avoid this problem by using properties instead of iVars. Then you can use
setValue:forKey:andvalueForKey:to get and set the properties.Here is the Apple documentation:
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Protocols/NSKeyValueCoding_Protocol/Reference/Reference.html