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: ",[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?

Kindly suggest.
_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to