What is the difference between objectForKey and valueForKey?
来源:互联网 发布:java自定义日志输出 编辑:程序博客网 时间:2024/05/09 08:17
Q:What is the difference between objectForKey and valueForKey?I looked both up in the documentation and they seemed the same to me.
--------------------------------------------------------------------------------------------------------------------------------------------------
A:"objectForKey:" is an NSDictionary method. An NSDictionary is a collection class similar to an NSArray, except instead of using indexes, it uses keys to differentiate between items. A key is an arbitrary string you provide. No 2 objects can have the same key (just as no 2 objects in an NSArray can have the same index).
"valueForKey: is KVC method. It works with ANY class. "valueForKey" allows you to access an instance variable using a string. So for instance, if I have an Account class with an instance variable accountNumber, I can do the following:
Using KVC, I can also do it like this:
Those are equivalent sets of statements.
I know you're thinking: wow, but sarcastically. KVC doesn't look all that useful. In fact, it looks "wordy". But when you want to change things at runtime, you can do lots of cool things that are much more difficult in other languages (but this is beyond the scope of your question).
If you want to learn more about KVC, there are many tutorials if you Google especially at Scott Stevenson's blog.
Hope that helps.
- What is the difference between objectForKey and valueForKey?
- Difference Between objectForKey and valueForKey in NSDictionary
- 【iOS】Difference Between objectForKey and valueForKey in NSDictionary
- What is the difference between test, [ and [[ ?
- what is the difference between the setTimeout and setInterval
- What is the difference between DHTML and the DOM?
- What is the difference between the mouseover and mouseenter events?
- What is the difference between AWT and SWT?
- What is the difference between User Control and Custom Control?
- What is the difference between an EXE and a DLL?
- What is the difference between XML and C or C ?
- What is the difference between SMOD and CMOD?
- what is the difference between little-endian and big-endian.
- What is the difference between procedural and nonprocedural language?
- What is the difference between a thread and a process?
- What is the difference between Microsoft TMG and UAG ?
- What is the Difference Between http and https?
- what is the difference between ELF files and bin files
- 错误的抉择,痛悔
- 网上看到的一个统计代码行工具
- 网上看到的一个统计代码行工具
- 【转】java.lang.Integer.toHexString(b[n] & 0XFF)中0XFF使用的必要性
- Android AudioManager控制系统声音的流程
- What is the difference between objectForKey and valueForKey?
- POJ1236解题报告 强连通分支+缩点
- 正确理解CRITICAL_SECTION
- MyEclipse小结
- UpdateData函数的 wincore.cpp Line:883错误
- div 和 span 的区别
- TinyMCE 编辑器
- 文本挖掘经典书籍推荐—THE TEXT MINING HANDBOOK(Advd. Approaches in Analyzing Unstructured Data)
- 芬兰VTT公司的研究报告:Data Mining Tools for Technology, 2008