> On Oct 6, 2014, at 10:12 AM, Devarshi Kulshreshtha 
> <[email protected]> wrote:
> 
> 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
>> 
>> 
>> That doesn't make any sense — it's illegal to pass a nil key to
>> setValue:ForKey:. Who is calling this method?
> 
> This method is automatically called, since I am invoking
> setValuesForKeysWithDictionary: in init method.
> 
>> Is there any way to achieve the same result in 'Scenario 1', may be by
>> using any API from objective c runtime?
>> 
>> 
>> Again, who is supposed to be calling setValue:forKey: if your init method
>> isn't calling it?
>> And why do you want to know the class of the key if it's clearly declared as
>> NSString already? It's always going to be a string.
> 
> Actually I am indirectly trying to identify class of property, through
> key parameter, the NSLog statement added within - setValue: forKey: is
> wrong, I was trying to do something like this:
> 
> - (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
> }

Assuming your values are objects, then of course this is going to return nil 
during -init*, the value hasn’t been set yet.

The ‘value’ passed is the incoming value, and you would probably want to check 
its class instead, if you do this at all.

But honestly this entire exercise seems to be exactly what NSCoding is designed 
for. Why not use that instead?

> 
> _______________________________________________
> 
> 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/david.duncan%40apple.com
> 
> This email sent to [email protected]

--
David Duncan


_______________________________________________

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