12.数据
2015-11-18 10:43
225 查看
原文:http://rypress.com/tutorials/objective-c/data-types/index
OC集成了所有的C的基本类型,并且定义了一些自己专属的数据类型。但是应用同样也需要一些高级的工具诸如strings,字典和日期。框架为我们定义了一些类来提供标准的面向对象的数据类型。
但是大多数的框架提供了对应的工厂方法,像这样:
这个创建方法为我们创建NSNumber对象并autoreleases它,在ARC出现之前非常方便,但是现在,上述两者原理上已经没有什么特殊区别了。
Pointer comparison uses the
Value comparison uses methods like
OC中数据类型
Primitives | NSNumber | NSDecimalNumber | NSString |
NSSet | NSArray | NSDictionary | Dates |
创建对象
在OC中有两种方式创建对象。第一,可以使用标准的alloc/init方式去创建。例如你可以按照如下示例创建NSNumber对象:NSNumber *twentySeven = [[NSNumber alloc] initWithInt:27];
但是大多数的框架提供了对应的工厂方法,像这样:
NSNumber *twentySeven = [NSNumber numberWithInt:27];
这个创建方法为我们创建NSNumber对象并autoreleases它,在ARC出现之前非常方便,但是现在,上述两者原理上已经没有什么特殊区别了。
对象比较
Comparing objects is one of the biggest pitfalls for Objective-C beginners. There are two distinct types of equality comparisons in Objective-C:Pointer comparison uses the
==operator to see if two pointers refer to the same memory address (i.e., the same object). It’s not possible for different objects to compare equal with this kind of comparison.
Value comparison uses methods like
isEqualToNumber:to see if two objects represent the same value. It is possible for different objects to compare equal with this kind of comparison.
相关文章推荐
- 逻辑电路 - 电磁感应
- IOS原生API解析和创建XML
- 开源爬虫框架各有什么优缺点?
- 在iOS开发中遇到的一些情况
- 使用apache CXF和maven开发Web Service
- mysql优化
- linux 下小技巧之-统计文件夹下面子文件夹下面的个数
- gles fage着色器的默认精度设置
- 如何写好博客——常用标点符号易错点正确用法汇总
- 帧动画切换卡顿解决
- Eclipse修改编码格式
- align和text-align的区别
- java jvm学习笔记三(class文件检验器)
- 关于防刷票的一些问题
- php 生成唯一id的几种解决方法
- Oracle数据库错误码大全
- PLSQL使用技巧
- Listview动态添加/删除数据
- Java的重写与调用父类方法问题
- ios 防止按钮快速点击造成多次响应的避免方法。