https://developer.apple.com/library/content/documentation/General/Conceptual/DevPedia-CocoaCore/DynamicTyping.html#//apple_ref/doc/uid/TP40008195-CH62-SW2

A variable is dynamically typed when the type of the object it points to is not checked at compile time. Objective-C uses the id data type to represent a variable that is an object without specifying what sort of object it is. This is referred to as dynamic typing.

Dynamic typing contrasts with static typing, in which the system explicitly identifies the class to which an object belongs at compile time. Static type checking at compile time may ensure stricter data integrity, but in exchange for that integrity, dynamic typing gives your program much greater flexibility. And through object introspection (for example, asking a dynamically typed, anonymous object what its class is), you can still verify the type of an object at runtime and thus validate its suitability for a particular operation.

The following example illustrates dynamic typing using a heterogeneous collection of objects:

NSArray *anArray = [NSArray arrayWithObjects:@"A string", [NSDecimalNumber zero], [NSDate date], nil];
NSInteger index;
for (index = 0; index < 3; index++) {
    id anObject = [anArray objectAtIndex:index];
    NSLog(@"Object at index %d is %@", index, [anObject description]);
}

The object pointed to by the variable at runtime must be able to respond to whatever messages you send to it; otherwise, your program throws an exception. The actual implementation of the method invoked is determined using dynamic binding.

The isa Pointer

Every object has an isa instance variable that identifies the object's class. The runtime uses this pointer to determine the actual class of the object when it needs to.

最新文章

  1. Xcode7.1环境下上架iOS App到AppStore 流程① (Part 一)
  2. Web Js 按键事件……Enter提交事件 Enter Js事件
  3. Python 爬取所有51VOA网站的Learn a words文本及mp3音频
  4. 【转】操作权限不够?教你开启Win7管理员帐户
  5. python_way ,day1 编译安装python3、基础及流程控制
  6. sqlite多表关联update
  7. 转自 z55250825 的几篇关于FFT的博文(二)
  8. 在VisualStudio 2012中通过SmallSharp压缩js及修改web.config
  9. myeclipse 不能添加非myeclipse开发的项目
  10. 在Mac上使用vundle自动安装vim插件,并用vim代替sourceinsight
  11. Windows下搭建deepnet环境
  12. java 服务治理办法
  13. EXCEL导入GridView,然后再汇入数据库.
  14. C#实现SQLSERVER数据库中有序GUID生成(NewSequentialId)
  15. tr 命令详解
  16. 在windows环境下更改某软件的窗口位置
  17. VueJs 源码分析 ---(二)实力化生命周期,以及解析模版和监听数据变化
  18. La nuova tecnologia del puntatore laser
  19. 你应该要知道的vue.js
  20. Android Studio原生库创建示例

热门文章

  1. 如何给自己的开源项目选择和添加 License
  2. bzoj2724: [Violet 6]蒲公英(分块)
  3. 关于写PPT
  4. pod 安装
  5. 文本处理三剑客之gawk
  6. web.xml中如何设置配置文件的加载路径
  7. Spark Mllib里的卡方检验
  8. Maven的学习资料收集--(九) 构建SSH项目以及专栏maven
  9. SpringBoot | 第十二章:RabbitMQ的集成和使用
  10. spring增强