Objective-C程序设计第10章---More on Variable and Data Types

本章注意点:

1. 实例变量显示地声明在implementation section(或者隐式地使用@synthesize)都是私有变量,子类不能直接访问。只能通过accessor方法访问。

@synthesize 可以让.m文件里直接使用变量名访问实例变量,而不用在前面加self.


2. 全局变量

通过extern int gMoveNumber 声明的变量可


3. static 变量

The users of the class would not need to know about this variable. Because it’s defined as a static variable in
the implementation file, its scope is restricted to that file.

You could write a method to retrieve the value of this variable if access is needed from outside the class.


4. 枚举类型
可以这样定义:
enum month { january = 1, february, march, april, may, june, july,
                    august, september, october, november, december };

        enum month amonth;

枚举类型主要以整形存在。
枚举类型不一定非得是Int类型,可以是其他类型的。
也可以这样定义。
enum iPhoneModels : unsigned short int { iPhone, iPhone3G,
iPhone3GS, iPhone4 iPhone4S, iPhone5, iPhone5C, iPhone5S };

也可以省略枚举类型名:
enum { east, west, south, north } direction;

5. typedef 用来定义类型。然后用这个类型去定义别的变量。
这样的好处是可读性增强。

typedef int Count;
Count j, n;

还可以这样定义:
Variables subsequently declared to be of type NumberObject , as in
NumberObject myValue1, myValue2, myResult;
are treated as if they were declared in the normal way in your program:
NSNumber *myValue1, *myValue2, *myResult;

规则:
To define a new type name with typedef , follow this procedure:
1. Write the statement as if a variable of the desired type were being declared.
2. Where the name of the declared variable would normally appear, substitute the new type
name.
3. In front of everything, place the keyword typedef .

还可以用来定义枚举类型
typedef enum { east, west, south, north } Direction;
Direction step1, step2;

3. 类型转换。
显示和隐式两种
显示:average = (float) total/n 
total, n 都是int类型。
1. If either operand is of type long double , the other is converted to long double , and
that is the type of the result.
2. If either operand is of type double , the other is converted to double , and that is the type
of the result.
3. If either operand is of type float , the other is converted to float , and that is the type
of the result.
4. If either operand is of type Bool , char , short int , or bitfield , or of an enumerated
data type, it is converted to int .
5. If either operand is of type long long int , the other is converted to long long int ,
and that is the type of the result.
6. If either operand is of type long int , the other is converted to long int , and that is
the type of the result.
7. If this step is reached, both operands are of type int , and that is the type of the result.






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值