object 初识

2018-06-10  本文已影响0人  奇梦人
Hello World

1.基本语法

(1)关键字
OC基本上关键字都是已 @ 开头,例如:@interface,@implementation,@public,但也有例外,例 id(可以指向任何类型)......

(2)字符串
java 字符串: String str="length";
oc 字符串: NSString *str=@"length";

(3)其他语法
基本类型:
整型 int integerType = 5;
浮点型 float floatType = 3.1415;
双浮点型 double doubleType = 2.2033;
字符型 char c=‘A’;

限定词:
长整型 long long int a;扩大内存
短整型 short short int a;小于和等于short大小

nil相当于null

(4)打印输出
OC的打印输出:NSLog(@"Hello World");
Java 打印输出:System.out.print("Hello World");

以下展示常用的NSLog打印
|通配符|| 描述|
%@ 对象
%d,%i 整型 (%i的老写法)
%hd 短整型
%ld,%lld 长整型
%u 无符整型
%f 浮点型和double型
%0.2f 精度浮点数,只保留两位小数

(5)BOOL类型
BOOL a=YES;
BOOL b=NO;
注意了!
BOOL a1=1;//true
BOOL b1=2;//false

BOOL类型的本质是char类型的:
YES (BOOL) 1
NO (BOOL)0
看到这大家或许看出来,a=1;b=0。布尔类型也可当作整数来使用。

上一篇下一篇

猜你喜欢

热点阅读