0

Good morning friends
I am new to IOS development and i want to know what is the difference between objectForKey and valueForKey. Who is the best in the way of performance?
Thanks in advance

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • 4
    Welcome to SO. As you enter a question (before clicking on Submit), SO will show you related and possibly duplicate answers to your own. Please check these before submitting your new question. You aren't the first person to ask this. – rmaddy Apr 23 '13 at 05:00
  • 1
    Googled your title - [first link](http://stackoverflow.com/questions/1062183/difference-between-objectforkey-and-valueforkey) – Michael Reneer Apr 23 '13 at 05:00

1 Answers1

1

valueForKey and objectForKey both will return the object for the given key. But here valuForKey is key-value coding.

If key does not start with “@”, invokes objectForKey:. If key does start with “@”, strips the “@” and invokes [super valueForKey:] with the rest of the key.

AMohan
  • 534
  • 1
  • 6
  • 15
  • However, sometimes, there is a practical difference which I don't understand clearly yet. `valueForKey` didn't work in SOGo-3.1.4's code trying to call an unavailable "method" `ASProtocolVersion` on the `context` object (`EXCEPTION: NAME:NSInvalidArgumentException REASON:-[WOContext ASProtocolVersion]: unrecognized selector sent to instance`), whereas `objectForKey` works (and is the usual way to query the `context` object elesewhere in the code). See https://github.com/inverse-inc/sogo/pull/217/files – imz -- Ivan Zakharyaschev Jul 20 '16 at 11:56