您的位置:首页 > 移动开发 > IOS开发

NSSet.h翻译

2015-07-02 17:27 344 查看
/* NSSet.h  是无序的集合,但是它保证数据的唯一性。当插入相同的数据时,不会有任何效果。集合是一种哈希表,运用散列算法,查找集合中的元素比数组速度更快,但是它没有顺序。
Copyright (c) 1994-2014, Apple Inc. All rights reserved.
*/

#import <Foundation/NSObject.h>
#import <Foundation/NSEnumerator.h>

@class NSArray, NSDictionary, NSString;

/**************** Immutable Set ****************/
/**************** 不可变的Set   ****************/
@interface NSSet : NSObject <NSCopying, NSMutableCopying, NSSecureCoding, NSFastEnumeration>

//  返回集合中对象的个数
@property (readonly) NSUInteger count;
//如果object是集合中的一员则返回这个object,否则返回null。
- (id)member:(id)object;
//返回一个NSEnumerator(枚举器)类型
- (NSEnumerator *)objectEnumerator;
//初始化
- (instancetype)init NS_DESIGNATED_INITIALIZER;
//初始化的时候加入
- (instancetype)initWithObjects:(const id [])objects count:(NSUInteger)cnt NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;

@end

@interface NSSet (NSExtendedSet)
//数组类型,set中所有的对象
@property (readonly, copy) NSArray *allObjects;
//返回集合中的第一个对象
- (id)anyObject;
// 判断集合是否包含对象anObject
- (BOOL)containsObject:(id)anObject;
//使用当前的集合生成字符串。可以重写description改变生成的字符串。
@property (readonly, copy) NSString *description;
- (NSString *)descriptionWithLocale:(id)locale;
// 判断两个集合的交集是否至少存在一个元素
- (BOOL)intersectsSet:(NSSet *)otherSet;
// 判断两个集合是否相等
- (BOOL)isEqualToSet:(NSSet *)otherSet;
// 判断集合是否是另一个集合(otherSet)的子集
- (BOOL)isSubsetOfSet:(NSSet *)otherSet;
// 类似于for循环
- (void)makeObjectsPerformSelector:(SEL)aSelector;
- (void)makeObjectsPerformSelector:(SEL)aSelector withObject:(id)argument;
//把一个对象加到原本集合 返回一个新NSSet * 无序的
- (NSSet *)setByAddingObject:(id)anObject NS_AVAILABLE(10_5, 2_0);
//把一个集合加到原本集合 返回一个新NSSet * 无序的
- (NSSet *)setByAddingObjectsFromSet:(NSSet *)other NS_AVAILABLE(10_5, 2_0);
//把一个数组加到原本集合 返回一个新NSSet * 无序的
- (NSSet *)setByAddingObjectsFromArray:(NSArray *)other NS_AVAILABLE(10_5, 2_0);
//遍历集合中的所有元素,obj就是集合中的元素 *stop BOOL类型的 控制什么时候停止遍历
- (void)enumerateObjectsUsingBlock:(void (^)(id obj, BOOL *stop))block NS_AVAILABLE(10_6, 4_0);
- (void)enumerateObjectsWithOptions:(NSEnumerationOptions)opts usingBlock:(void (^)(id obj, BOOL *stop))block NS_AVAILABLE(10_6, 4_0);

- (NSSet *)objectsPassingTest:(BOOL (^)(id obj, BOOL *stop))predicate NS_AVAILABLE(10_6, 4_0);
- (NSSet *)objectsWithOptions:(NSEnumerationOptions)opts passingTest:(BOOL (^)(id obj, BOOL *stop))predicate NS_AVAILABLE(10_6, 4_0);

@end

@interface NSSet (NSSetCreation)
//构造对象
+ (instancetype)set;
//创建集合对象,并且初始化集合中的数值,结尾必须使用nil标志
+ (instancetype)setWithObject:(id)object;
+ (instancetype)setWithObjects:(const id [])objects count:(NSUInteger)cnt;
+ (instancetype)setWithObjects:(id)firstObj, ... NS_REQUIRES_NIL_TERMINATION;
//用另外一个set对象构造
+ (instancetype)setWithSet:(NSSet *)set;
//用数组构造
+ (instancetype)setWithArray:(NSArray *)array;

//使用一组对象创建新的集合
- (instancetype)initWithObjects:(id)firstObj, ... NS_REQUIRES_NIL_TERMINATION;
//使用一个set来构造另一个set
- (instancetype)initWithSet:(NSSet *)set;
//使用一个set来构造另一个set flag YES 把里面的每一个对象都copy一份加到这个构造的set 如果flag 是NO 不做copy直接加到新集合中
- (instancetype)initWithSet:(NSSet *)set copyItems:(BOOL)flag;
//使用一个array来构造另一个set
- (instancetype)initWithArray:(NSArray *)array;

@end

/**************** Mutable Set ****************/
/**************** 可变的 Set 继承自NSSet****************/
@interface NSMutableSet : NSSet
//向集合中动态的添加对象
- (void)addObject:(id)object;
//删除集合中的一个对象
- (void)removeObject:(id)object;

- (instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;
//初始化Mutable Set
- (instancetype)init NS_DESIGNATED_INITIALIZER;
//创建可变的集合对像,并且初始化长度为numItems
- (instancetype)initWithCapacity:(NSUInteger)numItems NS_DESIGNATED_INITIALIZER;

@end

@interface NSMutableSet (NSExtendedMutableSet)
//把一个数组加到原本集合 返回一个新NSSet * 无序的
- (void)addObjectsFromArray:(NSArray *)array;
//一个set是否包含otherSet中的对象 如果有返回YES
- (void)intersectSet:(NSSet *)otherSet;

- (void)minusSet:(NSSet *)otherSet;
//移除集合里面的所有数据
- (void)removeAllObjects;
//把set和OtherSet的并集替换成set
- (void)unionSet:(NSSet *)otherSet;
//把一个set用otherSet替换了并把两个集合的交集加到set中
- (void)setSet:(NSSet *)otherSet;

@end
创建可变集合对象,并且初始化长度为6
@interface NSMutableSet (NSMutableSetCreation)
//创建可变集合对象,并且初始化长度为numItems
+ (instancetype)setWithCapacity:(NSUInteger)numItems;

@end

/**************** 继承自NSMutableSet的Counted Set ****************/

@interface NSCountedSet : NSMutableSet {
@private
id _table;
void *_reserved;
}
//创建NSMutableSet集合对像,并且初始化长度为numItems
- (instancetype)initWithCapacity:(NSUInteger)numItems; // designated initializer
//用数组构造
- (instancetype)initWithArray:(NSArray *)array;
//用set构造
- (instancetype)initWithSet:(NSSet *)set;
//统计重复对象的个数
- (NSUInteger)countForObject:(id)object;
//返回一个枚举类型
- (NSEnumerator *)objectEnumerator;
//添加一个元素到CountedSet
- (void)addObject:(id)object;
//移除CountedSet中的某一个元素
- (void)removeObject:(id)object;

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