I have a class with below interface:
@interface MyData : NSObject
@property (readwrite, strong) NSString *urlToParse;
@property (readwrite, strong) MappingElement *titleElement;
- (instancetype)initWithPlist:(NSString *)plistPath;
Its implementation is like this:
- (instancetype)initWithPlist:(NSString *)plistPath
{
if (self = [super init]) {
NSDictionary *plistData = [[NSDictionary alloc]
initWithContentsOfFile:plistPath];
[self setValuesForKeysWithDictionary:plistData];
}
return self;
}
#pragma mark KVC related methods
- (void)setValue:(id)value forKey:(NSString *)key
{
NSLog(@"key class: ",[[self valueForKey:key] class]); // it is printing nil, prints
correct value if key is initialized in init method
}
Now there are two scenarios:
Scenario 1: Do not initialize instance variables in initWithPlist:
method
In this case if I try to log class of key in setValue:forKey:
method,
it prints nil.
Scenario 2: Initialize instance variables in initWithPlist:
method
In this case if I try to log class of key in setValue:forKey:
method,
it prints NSString
and then MappingElement
.
Is there any way to achieve the same result in 'Scenario 1', may be by using any API from Objective=C runtime?