关于NSSet集合 anyObject的取值猜测
2015-07-20 20:12
549 查看
NSSet 内是无序的;
anyObject 官方解释
The object returned is chosen at the hash table’s convenience—the selection is not guaranteed to be random.
大概意思:从hash 表返回一个最近便捷的对象,不保证随机;
1直接打印anyObject返回值
2遍历字典
//
// main.m
// Getstart
//
// Created by 何晓文 on 15/7/20.
// Copyright © 2015年何晓文. All rights reserved.
//
#import <Foundation/Foundation.h>
int main(int argc,constchar * argv[]) {
NSSet *set = [NSSetsetWithObjects:@"1",@"a",@"2",@"b",
@"3",@"c",
@"4",@"d",
@"5",@"e",
@"6",@"f" ,nil];
NSLog(@"anyObject :%@",[setanyObject]);
for (id objin set) {
NSLog(@"---->%@", obj);
}
return 0;
}
发现取回的值与遍历的第一个元素一样;
2015-07-20 20:10:07.448 Getstart[648:35566] anyObject :2
2015-07-20 20:10:07.448 Getstart[648:35566] ---->2
2015-07-20 20:10:07.448 Getstart[648:35566] ---->a
2015-07-20 20:10:07.448 Getstart[648:35566] ---->3
2015-07-20 20:10:07.448 Getstart[648:35566] ---->b
2015-07-20 20:10:07.449 Getstart[648:35566] ---->4
2015-07-20 20:10:07.449 Getstart[648:35566] ---->c
2015-07-20 20:10:07.449 Getstart[648:35566] ---->5
2015-07-20 20:10:07.449 Getstart[648:35566] ---->d
2015-07-20 20:10:07.449 Getstart[648:35566] ---->6
2015-07-20 20:10:07.449 Getstart[648:35566] ---->e
2015-07-20 20:10:07.449 Getstart[648:35566] ---->f
2015-07-20 20:10:07.449 Getstart[648:35566] ---->1
修改元素后依然
anyObject 官方解释
The object returned is chosen at the hash table’s convenience—the selection is not guaranteed to be random.
大概意思:从hash 表返回一个最近便捷的对象,不保证随机;
1直接打印anyObject返回值
2遍历字典
//
// main.m
// Getstart
//
// Created by 何晓文 on 15/7/20.
// Copyright © 2015年何晓文. All rights reserved.
//
#import <Foundation/Foundation.h>
int main(int argc,constchar * argv[]) {
NSSet *set = [NSSetsetWithObjects:@"1",@"a",@"2",@"b",
@"3",@"c",
@"4",@"d",
@"5",@"e",
@"6",@"f" ,nil];
NSLog(@"anyObject :%@",[setanyObject]);
for (id objin set) {
NSLog(@"---->%@", obj);
}
return 0;
}
发现取回的值与遍历的第一个元素一样;
2015-07-20 20:10:07.448 Getstart[648:35566] anyObject :2
2015-07-20 20:10:07.448 Getstart[648:35566] ---->2
2015-07-20 20:10:07.448 Getstart[648:35566] ---->a
2015-07-20 20:10:07.448 Getstart[648:35566] ---->3
2015-07-20 20:10:07.448 Getstart[648:35566] ---->b
2015-07-20 20:10:07.449 Getstart[648:35566] ---->4
2015-07-20 20:10:07.449 Getstart[648:35566] ---->c
2015-07-20 20:10:07.449 Getstart[648:35566] ---->5
2015-07-20 20:10:07.449 Getstart[648:35566] ---->d
2015-07-20 20:10:07.449 Getstart[648:35566] ---->6
2015-07-20 20:10:07.449 Getstart[648:35566] ---->e
2015-07-20 20:10:07.449 Getstart[648:35566] ---->f
2015-07-20 20:10:07.449 Getstart[648:35566] ---->1
修改元素后依然
相关文章推荐
- Objective-C的内省(Introspection)用法小结
- Objective-C中常用的结构体NSRange,NSPoint,NSSize(CGSize),NSRect实例分析
- Objective-C中NSLog输出格式大全
- Swift调用Objective-C编写的API实例
- Swift、Objective-C、Cocoa混合编程设置指南
- Objective-c代码如何移植为Swift代码 Objective-c代码转移到Swift过程介绍
- Swift调用Objective-C代码
- objective-c中生成随机数的方法
- 在Swift中使用Objective-C编写类、继承Objective-C类
- Swift能代替Objective-C吗?
- Objective-C 消息传递机制详解
- 在一个项目中同时使用Swift和Objective-C代码混合编程的方法
- vm安装mac os x 10.7 lion
- objective-c(一)
- objective-c(二)
- objective-c(三)
- objective-c(四)-基本数据类型以及循环和选择结构
- objective-c(六)文件分离,合成存取方法,方法多参数,局部变量,self使用(未完成)
- windows下objective-c的cocoa框架编程,可以有图形界面哟