0

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?

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Devarshi
  • 16,440
  • 13
  • 72
  • 125
  • possible duplicate of [How to detect a property return type in Objective-C](http://stackoverflow.com/questions/769319/how-to-detect-a-property-return-type-in-objective-c) – Jesse Rusak Oct 07 '14 at 12:30
  • @JesseRusak thanks for the pointer, it seems similar, hence marking this posted question as resolved. – Devarshi Oct 07 '14 at 13:18

0 Answers0