您的位置:首页 > 移动开发 > Objective-C

关于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

修改元素后依然

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Objective-C