- 浏览: 582023 次
- 性别:
- 来自: 广州
文章分类
最新评论
-
JYY282:
[i][/i]
Ecshop与Shopex的比较 -
qq247890212:
我也遇见这问题了,真诡异。重新下载个猫换了就好了。 太浪费时间 ...
诡异:ClassNotFoundException: org.springframework.web.filter.CharacterEncoding
From:http://www.2cto.com/kf/201110/107291.html
Objective-C有3个动态特性
1,动态类型
Dynamic typing—determining the class of an object at runtime
运行时决定对象类型
2,动态绑定
Dynamic binding—determining the method to invoke at runtime
运行时决定方法调用
3,动态加载
Dynamic loading—adding new modules to a program at runtime
运行时加载新模块
如何理解Objective-C的3这个动态特性呢?
首先,动态类型,简单点说就是id 类型,可以理解为通用对象类型,一旦被赋值,可以被强制转化为其它类型。可以通过[obj isKindOfClass:aClass],来判断其具体类型,作相应操作。这一点在委托(delegate)中体现得比较充分
动态绑定是基于动态类型的,某个实例被确定后,其类型也是确定的,其对应的属性和方法将会因为类型的确定而确定,这就是动态绑定。
动态加载是程序启动时动态加载可执行代码和资源。例如:多国语言的程序,会在程序启动时只加载设定为某一种语言的资源,而不是全部加载。基于Utility Application的程序,分别在iPhone和iPad上运行的时候,只会加载对应的代码和资源。当然兼容视网膜技术的@2x 图片加载也是这样的
From:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/CocoaObjects.html%23//apple_ref/doc/uid/TP40002974-CH4-SW32
The Dynamism of Objective-C
Objective-C is a very dynamic language. Its dynamism frees a program from compile-time and link-time constraints and shifts much of the responsibility for symbol resolution to runtime, when the user is in control. Objective-C is more dynamic than other programming languages because its dynamism springs from three sources:
Dynamic typing—determining the class of an object at runtime
Dynamic binding—determining the method to invoke at runtime
Dynamic loading—adding new modules to a program at runtime
For dynamic typing, Objective-C introduces the id data type, which can represent any Cocoa object. A typical use of this generic object type is shown in this part of the code example fromListing 2-2:
id word;
while (word = [enm nextObject]) {
// do something with 'word' variable....
}
The id data type makes it possible to substitute any type of object at runtime. You can thereby let runtime factors dictate what kind of object is to be used in your code. Dynamic typing permits associations between objects to be determined at runtime rather than forcing them to be encoded in a static design. Static type checking at compile time may ensure stricter data integrity, but in exchange for that stricter 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. (Of course, you can always statically check the types of objects when you need to.)
Dynamic typing gives substance to dynamic binding, the second kind of dynamism in Objective-C. Just as dynamic typing defers the resolution of an object’s class membership until runtime, dynamic binding defers the decision of which method to invoke until runtime. Method invocations are not bound to code during compilation; they are bound only when a message is actually delivered. With both dynamic typing and dynamic binding, you can obtain different results in your code each time you execute it. Runtime factors determine which receiver is chosen and which method is invoked.
The runtime’s message-dispatch machinery enables dynamic binding. When you send a message to a dynamically typed object, the runtime system uses the receiver’s isa pointer to locate the object’s class, and from there the method implementation to invoke. The method is dynamically bound to the message. And you don’t have to do anything special in your Objective-C code to reap the benefits of dynamic binding. It happens routinely and transparently every time you send a message, especially one to a dynamically typed object.
Dynamic loading, the final type of dynamism, is a feature of Cocoa that depends on Objective-C for runtime support. With dynamic loading, a Cocoa program can load executable code and resources as they’re needed instead of having to load all program components at launch time. The executable code (which is linked prior to loading) often contains new classes that become integrated into the runtime image of the program. Both code and localized resources (including nib files) are packaged in bundles and are explicitly loaded with methods defined in Foundation’s NSBundle class.
This “lazy-loading” of program code and resources improves overall performance by placing lower memory demands on the system. Even more importantly, dynamic loading makes applications extensible. You can devise a plug-in architecture for your application that allows you and other developers to customize it with additional modules that the application can dynamically load months or even years after the application is released. If the design is right, the classes in these modules will not clash with the classes already in place because each class encapsulates its implementation and has its own namespace.
Dynamic typing—determining the class of an object at runtime
Dynamic binding—determining the method to invoke at runtime
Dynamic loading—adding new modules to a program at runtime
发表评论
-
Objective-C 与 C++ 的异同
2013-04-02 12:03 1401http://www.cnblogs.com/y041039 ... -
Cocos2D-X是全球知名的开源跨平台手机游戏引擎
2013-01-22 10:05 2757http://www.oschina.net/p/cocos ... -
iOS Keyboard 键盘高度变化 自适应
2013-01-15 15:43 3252[[NSNotificationCenter default ... -
iOS使用自定义字体
2012-11-27 12:11 12145From: http://blog.csdn.net/csy1 ... -
4 款类似 Facebook/Path 切换效果的 iOS 组件
2012-11-27 12:03 2200From: http://blog.csdn.net/lia ... -
Path 2.0的UI界面设计详细介绍
2012-11-27 11:56 1471如Path的创始人Dave Morin ... -
史上最全的App Store邮箱列表
2012-11-27 11:51 1272From: http://roybaby.blog.51cto ... -
iOS从info.plist 获取项目的名称及版本号
2012-11-16 10:54 1675From: http://blog.sina.com.cn/s ... -
MapKit annotation drag and drop with callout info update
2012-10-13 10:38 2409http://hollowout.blogspot ... -
NSArray 或NSDictionary 调用writeToFile方法失败原因
2012-08-31 10:03 4489NSArray 或NSDictionary 调用writeTo ... -
如何让IOS应用从容地崩溃
2012-08-30 15:25 1621From: http://www.cocoachina.com ... -
iOS中判断设备系统版本
2012-08-29 17:17 31716在iOS开发中,经常要考虑系统的向下兼容,如果使用 ... -
iOS 汉字转拼音
2012-08-21 16:42 1471From: http://www.cnblogs.com/v2 ... -
iOS模拟器截图工具
2012-08-17 16:35 1663From: http://magicalboy.com/ios ... -
XCode下的iOS单元测试
2012-08-10 17:47 1171From: http://mobile.51cto.com/ ... -
AFNetworking
2012-08-08 10:54 4655AFNetworking on github: https:/ ... -
Wrapping Conventions
2012-08-01 15:54 826Wrapping Conventions ... -
Core Animation如何使显式动画结束时的值直接作用Layer
2012-08-01 14:51 3799(1)使用隐式动画会直接改变layer的属性值,如: ima ... -
How To Debug Memory Leaks with XCode and Instruments Tutoria
2012-07-31 16:30 1058From: http://www.raywenderlich. ... -
Using Properties in Objective-C Tutorial
2012-07-31 16:27 932From: http://www.raywenderlich. ...
相关推荐
- **动态性**:Objective-C的动态特性使得它能够在运行时向对象发送消息,从而实现灵活的功能扩展。 - **简洁性**:尽管功能强大,但Objective-C的语法相对简单,易于学习和使用。 #### Cocoa框架概述 Cocoa是苹果...
### iPhone开发:Objective-C语法入门 #### 一、Objective-C简介 Objective-C是一种面向对象的编程语言,它是在C语言的基础上扩展而成的。Objective-C主要应用于苹果公司的操作系统上,包括macOS、iOS、watchOS以及...
Objective-C的语法在很多方面与C语言相似,但增加了类、消息传递等面向对象的特性。 1. **方法调用**:在Objective-C中,方法调用通过`[对象 方法]`的形式进行。例如,`[object method];`或`[object ...
- **特点**:Objective-C保留了C语言的所有特性,并在此基础上增加了面向对象的特性,使得它成为一种强大的语言。 #### 二、Objective-C编程基础知识 - **变量与数据类型**:Objective-C支持多种数据类型,包括基本...
苹果iphone开发系列:Objective-C初學者指南 该种语言的最大特色是中括号【】
接下来,您可以开始探索Objective-C的各种特性和功能,逐步深入学习和开发iOS应用程序了。希望这份指南能够帮助您顺利入门,祝您学习进步! 总结来说,在Windows系统下搭建Objective-C开发环境虽然不像在Mac OS X上...
Objective-C是一种面向对象的编程语言,它是C语言的超集,特别为苹果的iOS和macOS平台的软件开发而设计。Objective-C通过引入Smalltalk的影响,支持类、方法和属性等面向对象特性,使得程序员能够构建复杂的软件系统...
1. **通过Objective-C源代码**:这是最常见的交互方式,当编写和编译Objective-C类和方法时,编译器会自动生成一些数据结构和函数,用于支持语言的动态特性。这些数据结构包含了类定义和协议定义中的信息,如方法...
Objective-C.2.0是Apple公司开发的面向对象的编程语言,它是基于C语言的,同时也融合了Smalltalk的特性。Objective-C在苹果的iOS和macOS平台上被广泛用于开发原生应用程序。以下是一些Objective-C.2.0的关键知识点:...
### iPhone SDK编程入门:使用Objective-C详解 #### 获取与理解iPhone SDK 对于任何希望进入iPhone应用开发领域的开发者而言,掌握如何获取与使用iPhone SDK(Software Development Kit)是至关重要的第一步。SDK...
本书《Beginning iPhone SDK Programming with Objective-C》是一本专为初学者设计的指南,旨在帮助读者快速掌握如何使用Objective-C语言进行iPhone应用程序开发。书中通过浅显易懂的语言和丰富的示例代码,为读者...
本教程将通过一系列的PPT课件,引导你快速入门Objective-C,这些课件覆盖了从基础到高级的重要概念,是《iPhone与iPad开发实战》一书中关于语言学习的前半部分内容。 首先,我们从"第一讲 Objective-C概述"开始,这...
iOS 7 Programming Fundamentals: Objective-C, Xcode, and Cocoa Basics by Matt Neuburg (Author) Publisher: O’Reilly Media (October 2013) Language: English ISBN-10: 1491945575 ISBN-13: 978-...
Objective-C作为一种动态的面向对象语言,是C语言的一种扩展。它以其易读性和强大的面向对象设计能力著称,是MacOS X以及iPhone操作系统的主要开发语言。Cocoa作为MacOS X的核心应用程序框架,包含了大量用于快速...
8. Foundation框架:Objective-C的开发离不开Foundation框架,它提供了一系列基础数据类型、集合类(如NSArray、NSDictionary)、线程管理等工具。 9. iOS SDK:对于iOS开发,还需要了解UIKit框架,它包含了构建...
- **特点**:Objective-C支持类、消息传递、继承等面向对象编程特性,并与C语言兼容,允许开发者直接在Objective-C代码中使用C代码。 ##### 2. 基础语法 - **变量和数据类型**:Objective-C支持多种内置数据类型,...
1. Objective-C简介:Objective-C是一种通用、面向对象的编程语言,主要用于iOS和OS X应用的开发。它是由Smalltalk语言的面向对象特性和C语言的灵活性相结合而成的,由Next公司开发,并由苹果公司在Mac OS X和iOS...
1. **语法特性**:Objective-C是在C语言的基础上扩展的,保留了C的语法特性,同时引入了消息传递机制,使得它具有面向对象的能力。 2. **类和对象**:Objective-C中的所有数据结构都是基于类的,类是对象的模板,而...
尽管了解Objective-C运行时系统的细节不是编写Cocoa应用程序所必需的,但掌握这些知识可以让开发者更好地理解Objective-C语言的底层机制,并在必要时利用这些强大的特性来构建更加复杂和灵活的应用程序。通过深入...