• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Obtaining class of key at runtime
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Obtaining class of key at runtime


  • Subject: Obtaining class of key at runtime
  • From: Devarshi Kulshreshtha <email@hidden>
  • Date: Mon, 06 Oct 2014 20:13:50 +0530

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@hidden)

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:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Obtaining class of key at runtime
      • From: Jens Alfke <email@hidden>
  • Prev by Date: Re: A Stack of Editors
  • Next by Date: Re: Obtaining class of key at runtime
  • Previous by thread: Re: Validate NSDocument on Quit
  • Next by thread: Re: Obtaining class of key at runtime
  • Index(es):
    • Date
    • Thread