objective-c
iamfjg
这个作者很懒,什么都没留下…
展开
-
objective-c方法
方法定义了类和类实例在运行时所表现出的行为。分2种:class method、instance method. 方法能够声明在:interface、protocol、以及category。 1、语法: Method type:+代表类方法,-代表实例方法。 Return type:要放在括号中。没有返回值,就写void。id是一个特殊的Objective-C类型。 ...原创 2015-07-10 15:10:57 · 142 阅读 · 0 评论 -
Message Dispatch
The receiving object (i.e., receiver) of a message determines at runtime which of its instance methods to invoke. The Objective-C syntax for sending a message to (i.e., invoking a method on) an ...原创 2015-11-29 01:30:35 · 171 阅读 · 0 评论 -
Filling in the gaps—floating-point numbers
浮点常量也可以表示成科学或指数计数法。例如,下面的2句变量声明会初始化为相同的值: float a = 0.0001; float b = 1e-4; The e can be thought of as representing “times 10 to the power of.” On the iPhone,as with most modern platforms,f...原创 2015-11-28 23:05:55 · 125 阅读 · 0 评论 -
Counting on your fingers—integral numbers
An integer is a whole number that can be negative or positive.The values 27,-5,and 0 are all valid integer values,but 0.82 isn't because it contains a decimal point. By default,variables of type ...原创 2015-11-28 22:28:30 · 80 阅读 · 0 评论 -
Creating and destroying objects
In Objective-C it takes two steps to create an object;in order,you must. Allocate memory to store the new object.. Initialize the newly allocated memory to appropriate values.An object isn't fully fun...原创 2015-11-27 22:31:56 · 107 阅读 · 0 评论 -
用Category来扩展一个类
想要给一个类添加方法和行为,但不想创建一个全新的子类。 在Objective-C中,可以用categories来定义并实现属性和方法,之后再将它们附加到一个类上。 假设你想要扩展NSString类,给它加一些方法来帮助你创建HTML文本。那么这个category头文件就会看起来像这样: @interface NSString (HTMLTags) 在@interface关键字...原创 2015-11-24 23:39:47 · 93 阅读 · 0 评论 -
给自定义类加类方法
在Objective-C中,你可以向类或对象发送消息来完成某件事。如果你想要你的自定义类能够回应某消息,就需要首先编写一个类方法。 类方法以+号开头。例如: +(void)writeDescriptionToLogWithThisDate:(NSDate *)date; 类的实现中这么写: +(void)writeDescriptionToLogWithThisDate:(N...原创 2015-11-24 22:52:12 · 184 阅读 · 0 评论 -
用Objective-C编写一个终端应用
在main函数中,必须建立一个autorelease pool,Objective-C用它来管理内存。 编译代码用的是clang命令,它的一些选项有: -fobjc——Objective-C是使用的编程语言 -arc——Automatic Reference Counting -framework——链接到Foundation框架 -o——创建的可执行文件的名字 注意:如...原创 2015-11-24 20:38:13 · 259 阅读 · 0 评论 -
Objective-C介绍
Objective-C是一门用于在Apple的OS X以及iOS(iPod,iPhone,iPad)平台上开发应用的主要编程语言。最近几年,这些平台成为了最流行的编程环境。成功的一个关键原因要归功于Objective-C的特性。 2007年,Apple发布了Objective-C 2.0版。向其中加入了许多新特性,包括declared以及synthesized properties,do...原创 2015-07-10 20:34:37 · 215 阅读 · 0 评论 -
Objective-C Protocol
已经学习了Objective-C类的基本元素和结构,但是该语言还提供了许多额外的特性用于开发类。本节说的就是protocols。 一个protocol声明了可以让其他任何类实现的方法和属性。 一个类接口是和一个特定的类相关联的,这就形成了一个类层次结构。 而,protocol并不与任何特定类关联,所以它可以被用来捕捉一些并没有层次关系的类里的相似点。 proto...原创 2015-07-10 15:19:13 · 58 阅读 · 0 评论 -
Message Forwarding
The object type can either be specified in the code and statically bound at compile time (static typing) or be unspecified with its type resolved at runtime (dynamic typing). In either case, at runti...原创 2015-11-29 02:02:10 · 75 阅读 · 0 评论