博客
关于我
NSSet集合 无序的 不能重复的
阅读量:794 次
发布时间:2023-02-17

本文共 1748 字,大约阅读时间需要 5 分钟。

//// main.m NSSet集合//// Created by MAC on 15/12/15.// Copyright © 2015年 MAC. All rights reserved.////#import // 无序集合,效率较高且无法索引int main(int argc, const char * argv[]) {    @autoreleasepool {        // 无序集合,效率较高且无法索引        NSArray *array = @[@"one", @"two", @"three", @"three", @"four", @"five"];        NSLog(@"%@", array);                // 初始化集合        NSSet *set = [NSSet setWithArray:array];        NSLog(@"%@", set);                // 可以赋值初始化        NSSet *set1 = [NSSet setWithObjects:@"1", @"one", @"2", @"2", @"3", @"4", array, nil];        NSSet *set2 = [NSSet setWithObjects:@"1", @"one", @"2", @"2", @"3", @"4", nil];        NSLog(@"%@", set1);                // 从另一个集合中初始化        NSSet *set3 = [NSSet setWithSet:set1];        NSLog(@"%@", set3);                // 获取集合大小(不包括重复元素)        NSUInteger count = [set count];        NSLog(@"%lu", count);                // 枚举集合中的元素        NSEnumerator *e = [set objectEnumerator];        NSString *s;        while ((s = [e nextObject]) != nil) {            NSLog(@"%@", s);        }        NSLog(@"------");                // 判断某个对象是否是集合成员        id a = [set member:@"one"];        NSLog(@"%@", a);                // 判断集合是否包含某个成员        BOOL r = [set containsObject:@"one"];        NSLog(@"%d", r);                // 将集合转换为数组        NSArray *array1 = set.allObjects;        NSLog(@"%@", array1);                // 获取集合中的任意一个对象        id aa = [set anyObject];        NSLog(@"%@", aa);                // 判断两个集合是否相等        r = [set isEqualToSet:set1];        NSLog(@"%@", r ? @"YES" : @"NO");                // 判断两个集合的交集        r = [set intersectsSet:set1];        NSLog(@"%d", r);                // 判断一个集合是否是另一个的子集        r = [set2 isSubsetOfSet:set1];        NSLog(@"%d", r);    }    return 0;}

转载地址:http://brjfk.baihongyu.com/

你可能感兴趣的文章
OA项目之会议通知(查询&是否参会&反馈详情)
查看>>
Vue.js 学习总结(13)—— Vue3 version 计数介绍
查看>>
OA项目之我的会议(会议排座&送审)
查看>>
OA项目之我的会议(查询)
查看>>
OA项目之我的审批(会议查询&会议签字)
查看>>
OA项目之项目简介&会议发布
查看>>
ObjC的复制操作
查看>>
Object c将一个double值转换为时间格式
查看>>
object detection之Win10配置
查看>>
object detection训练自己数据
查看>>
object detection错误Message type "object_detection.protos.SsdFeatureExtractor" has no field named "bat
查看>>
object detection错误之Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
查看>>
object detection错误之no module named nets
查看>>
Object of type 'ndarray' is not JSON serializable
查看>>
Object Oriented Programming in JavaScript
查看>>
object references an unsaved transient instance - save the transient instance before flushing
查看>>
Object 类的常见方法有哪些?
查看>>
Object-c动态特性
查看>>
Object.assign用法
查看>>
Object.create
查看>>