第15章:数字,字符串和集合
来源:互联网 发布:网络安全技术与实践 编辑:程序博客网 时间:2024/05/01 05:45
一、数字对象
1.数据类型与数字对象的区别?
基本数据类型有:int型,float型,long型。但它们不是对象,不能够向他们发送消息
如果希望基本数据类型存储到对象中,可以使用NSNumber类,它会依据这些数据的类型来创建对象。
2.数字对象的创建和初始化方法
第一种方法:使用"创建和初始化方法"
这些方法以numberWith开头,紧接数据的类型,如numberWithLong: , numberWithFloat等。
例:
NSNumber *myNumber;
myNumber = [NSNumber numberWithInt: 100];
第二种方法:使用"初始化实例方法"
使用实例方法将以前创建的NSNumber对象设置为指定的值,这些方法以initWith开头,如initWithLong:,initWithFloat等
例:
NSNumber *myNumber;
myNumber = [[NSNumber alloc] initWithInt : 50];
3.数字对象的检索
检索实例的方法使用实例方法:数据类型+Value。比如:charValue,shortValue,intValue等。
例:
NSNumber *myNumber = [NSNumber numberWithInt : 100];
myInt = [myNumber intValue];
NSLog(@"%i",[myNumber intValue]);
打印输出: 100
4.实例方法isEqualToNumber和compare这二个方法的使用
isEqualToNumber:是比较二个NSNumber对象的数值。程序会返回一个BOOL值,查看这二个值是否相等。
compare:测试一个值是否在数值上小于,等于或大于另一个值。
例:[intNumber compare: floatNumber];
如果intNumber的数值小于floatNumber的数值,返回NSOrderedAscending
如果intNumber的数值大于floatNumber的数值,返回NSOrderedDscending
如果intNumber的数值等于floatNumber的数值,返回NSOrderedSame
Return a set containing the results of invoking valueForKey:
on each of the receiving set's members.
Parameters
- key
The name of one of the properties of the receiving set's members.
Return Value
A set containing the results of invoking valueForKey:
(with the argument key) on each of the receiving set's members.
Discussion
The returned set might not have the same number of members as the receiving set. The returned set will not contain any elements corresponding to instances of valueForKey:
returning nil
(note that this is in contrast with NSArray
’s implementation, which may putNSNull
values in the arrays it returns).
Invokes setValue:forKey:
on each of the set’s members.
Parameters
- value
The value for the property identified by key.
- key
The name of one of the properties of the set's members.
- 第15章:数字,字符串和集合
- 15-数字、字符串和集合
- 数字,字符串 和集合
- 数字、字符串和集合
- 数字,字符串 和集合
- object-c Foundation和数字、字符串、集合 第九天
- [学习笔记—Objective-C]《Objective-C 程序设计 第6版》第十五章 数字 字符串和集合
- 【第2章】Python基本元素:数字、字符串和变量
- 黑马程序员——Objective-C程序设计(第4版)学习笔记之15-数字、字符串和集合——黑马 IOS 技术博客
- 《c 和指针》第9章第16题——数字字符串格式化输出
- ObjC学习9-Foundation框架之数字、字符串和集合
- OC基础12:数字、字符串和集合1
- OC基础13:数字、字符串和集合2
- Freemarker 操作字符串,数字,集合
- Python学习第一篇之python 连接字符串和数字
- 《Python语言及其应用》读书笔记(1)之第2章Python基本元素:数字、字符串和变量(关键词:数字/字符串/变量)
- 第11章,字符串和字符串函数
- 字符串和数字
- 日志收集之flume-ng源码分析
- 11111
- 一步步学习微软InfoPath2010和SP2010--第十一章节--创建批准流程
- Vector和ArrayList的区别
- java开发环境配置
- 第15章:数字,字符串和集合
- Ceph-Openstack学习笔记
- ubuntu13.10 安装rpm包
- 第九届湖南省ACM—ICPC程序设计大赛 搞笑版费马大定理
- 【layout】fill_parent和wrap_content的区别
- open/read/write和fopen/fread/fwrite的区别
- C# 获取窗口句柄并且关闭应用程序
- gcc 和g++编译选项详解
- usc@1002:项目投标