IOS开发笔记(8)Foundation Kit 学习
来源:互联网 发布:伤感网络歌曲排行榜 编辑:程序博客网 时间:2024/06/15 09:34
http://blog.csdn.net/xiaofansong/article/details/8423630
//“==”运算符只判断两个字符串的指针数值,而不是它们所指的对象,以下例子请区别:
NSString *thing1 = @"hello,8";
NSString *thing2 = [NSString stringWithFormat:
@"hello,%d",8];
if ([thing1 isEqual: thing2]){
NSLog(@"Yes,they are the same.");
} else {
NSLog(@"NO,they are not the same.");
}
if (thing1 == thing2){
NSLog(@"thing1 == thing2");
} else{
NSLog(@"thing1 != thing2");
}
输出:
2012-12-24 09:42:36.345 Kit学习[459:403] Yes,they are the same.
2012-12-24 09:42:36.345 Kit学习[459:403] thing1 != thing2
2.集合
集合类:NSArray 、NSDictionary
1)NSArray
NSArray是Cocoa的一个类,用来存储对象的有序列表,可以在NSArray中放入任意类型的对象。
NSArray中只能存储Objective-C的对象,而不能存储C语言中的基本数据类型,如int,float,enum,struct,或者NSArray中的随机指针。同时,也不能在NSArray中存储nil(对象的零值或NULL值)。
- // 创建数组 arrayWithObjects:
- NSMutableArray *array;
- array = [NSArray arrayWithObjects:
- @"one", @"two", @"three", nil]; //列表结尾添加nil表示列表结束
- // 获取对象个数 count:
- NSLog(@" the count of array is: %ld",[array count]);
- // 获取特定索引处的对象 objectAtIndex:
- int i;
- for (i = 0 ; i < [array count]; i++)
- {
- NSLog(@"index %d has %@",
- i,[array objectAtIndex:i]);
- }
- // 将字符串切分成数组 componentsSeparatedByString:
- NSString *str = @"oop : ack : elf : com : cn : net";
- NSArray *arr = [str componentsSeparatedByString:@" : "];
- NSLog(@"str is : %@",str);
- NSLog(@"arr is :");
- for (NSString *s in arr)
- {
- NSLog(@"\"%@\"",s);
- }
- // 合并数组并创建字符串 componentsJoinedByString:
- NSLog(@"合并数组到NSArray.");
- str = [arr componentsJoinedByString:@" $"];
- NSLog(@"str is : %@",str);
- NSLog(@"arr is :");
- for (NSString *s in arr)
- {
- NSLog(@"\"%@\"",s);
- }
输出结果
2012-12-24 10:22:56.310 Kit学习[688:403] index 0 has one
2012-12-24 10:22:56.311 Kit学习[688:403] index 1 has three
2012-12-24 10:22:56.312 Kit学习[688:403] the count of array is: 3
2012-12-24 10:22:56.312 Kit学习[688:403] index 0 has one
2012-12-24 10:22:56.313 Kit学习[688:403] index 1 has two
2012-12-24 10:22:56.313 Kit学习[688:403] index 2 has three
2012-12-24 10:22:56.314 Kit学习[688:403] str is : oop : ack : elf : com : cn : net
2012-12-24 10:22:56.314 Kit学习[688:403] arr is :
2012-12-24 10:22:56.315 Kit学习[688:403] "oop"
2012-12-24 10:22:56.315 Kit学习[688:403] "ack"
2012-12-24 10:22:56.315 Kit学习[688:403] "elf"
2012-12-24 10:22:56.316 Kit学习[688:403] "com"
2012-12-24 10:22:56.316 Kit学习[688:403] "cn"
2012-12-24 10:22:56.317 Kit学习[688:403] "net"
2012-12-24 10:22:56.317 Kit学习[688:403]合并数组到NSArray.
2012-12-24 10:22:56.318 Kit学习[688:403] str is : oop $ack $elf $com $cn $net
2012-12-24 10:22:56.318 Kit学习[688:403] arr is :
2012-12-24 10:22:56.333 Kit学习[688:403] "oop"
2012-12-24 10:22:56.334 Kit学习[688:403] "ack"
2012-12-24 10:22:56.334 Kit学习[688:403] "elf"
2012-12-24 10:22:56.335 Kit学习[688:403] "com"
2012-12-24 10:22:56.335 Kit学习[688:403] "cn"
2012-12-24 10:22:56.336 Kit学习[688:403] "net"
- IOS开发笔记(8)Foundation Kit 学习
- IOS学习笔记之三:Foundation Kit详解(第一部分)
- IOS学习笔记之四:Foundation Kit详解(第二部分)
- iPhone 开发 (十一)Foundation kit 基础
- 黑马程序员——Objecttive-C学习笔记(四):Foundation Kit
- 黑马程序员——Objective-C学习笔记(五):foundation Kit (续)
- Objective-C学习笔记第八章Foundation Kit快速教程
- iOS Swift+Foundation学习笔记
- Objective-C学习笔记(一)------Foundation Kit快速学习
- ios笔记--Foundation框架学习笔记
- Foundation Kit快速教程复习笔记
- 【IOS学习】AV Foundation 学习笔记
- 黑马程序员-IOS学习笔记(十二)Foundation框架
- Foundation Kit
- Foundation Kit
- Foundation kit
- IOS开发笔记23-Foundation框架(上)
- IOS开发笔记24-Foundation框架(下)
- Servlet 中文乱码问题及解决方案剖析
- 多个commit 合并为一个patch
- resin3.X那些事之resin.conf
- delphi中临界操作方法
- VBS基础篇 - 对象(6) - Folder对象
- IOS开发笔记(8)Foundation Kit 学习
- Linux入门
- easyui datagrid editor checkbox 单击事件
- POJ2996
- maven pom文件详解
- 引用与指针的区别
- VBS基础篇 - 对象(7) - TextStream对象
- vs2008 设置文件
- _itoa atoi、atof、itoa、itow _itoa_s 类型转换使用说明