首页 技术 正文
技术 2022年11月19日
0 收藏 426 点赞 3,266 浏览 1206 个字

1、Objective-C中的数据类型:

  • Objective-C中的基本数据类型有:int、char(-128-127)、float、double、BOOL,Byte(0-255)
  • Id类型相当于(等价与)NSObject *类型

  (在iOS中,int类型可使用NSInteger / NSUInteger表示;float / double类型可使用CGFloat表示;后者可以根据系统位数长度[32位/64位]自动选择实际数据类型)

  OC中对象数据类型以指针形式表示(例如:NSString *str = @”Hello World!”;)

2、数据类型转换:

  • 自动类型转换:将范围小的数据类型值转换到范围大的类型值;

  Byte,short,char->int->long->float->double

  Byte short char之间不能互相转换,他们三者在计算时首先会转换成int类型

  • 强制类型转换:(类型)变量或数值或对象

  Byte b1 = 250(160); Byte b2 = 10; Byte b3 = b1 + b2; nslog(@”b3=%d”,b3);

  Byte=unsigned char    NSinteger CGfloat

  Int a = 38;int b = 100; float c = a /b(float c = (float)a/b);

  强制类型转换:

 int a = ;
int b = ;
float f = (float)a/b; //可以使用"(数据类型)变量 "这种语法强制转换类型,做强制类型转换时,要考虑一下 数据是否会溢出。
NSLog(@"f=%f",f); Byte b = ;//Byte 是oc重定义为Uint 范围是0 - 255 不能赋给负值 BOOL b = YES;//布尔类型有非零既真的说法 所以YES=1 NO=0

3、常量、变量(注意:以及变量的命名规范):

  标识符由字母、下划线、$、数字组成:

 int a;
int $a;
int _a;
//int 1_a; 错的
int A;
//int if; 错的
//int a*; 错的
8 NSString *str = @"abc";//""是c里的字符串 @""是oc里的字符串

4、运算符与表达式:

  • 算数运算符:+、-、*、/、%、++、–
  • 比较运算符:==、!=、>、>=、<、<=
  • 逻辑运算符:!、&&、||
  • 赋值运算符:=、+=、-=、*=、/=、%=
  • 运算优先级:

  () //运算优先级高

  !、*、/、%

  +、-

  ==、!=、>、>=、<、<=

  &&、||  

  +=、-=、*=、/=、%=

  = //运算优先级低

5、学习参考网站:

http://developer.apple.com

http://www.cocoachina.com

http://www.macx.cn

http://www.code4app.com

http://ui4app.com

  IT综合类网站:

http://www.36kr.com

http://www.51cto.com

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,093
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,570
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,417
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,190
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,825
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,908