17- (id)initWithEnumerator:(NSEnumerator*)enumerator;
19+ (instancetype)enumeratorWithCollection:(
id)collection;
23@interface OOWeakSet (OOPrivate)
36- (id)initWithCapacity:(NSUInteger)capacity
38 if ((
self = [super
init])) {
50 return [[[
self alloc] init] autorelease];
53+ (instancetype)setWithCapacity:(NSUInteger)capacity
55 return [[[
self alloc] initWithCapacity:capacity] autorelease];
67 NSMutableString* result = [
NSMutableString stringWithFormat:@"<%@ %p>{", [
self class],
self];
71 while ((
object = [selfEnum nextObject])) {
73 [
result appendString:@", "];
78 if ([
object respondsToSelector:
@selector(shortDescription)])
79 desc = [
object shortDescription];
81 desc = [
object description];
83 [
result appendString:desc];
86 [
result appendString:@"}"];
92- (id)copyWithZone:(NSZone*)zone
100- (id)mutableCopyWithZone:(NSZone*)zone
105- (BOOL)isEqual:(
id)other
107 if (![other isKindOfClass:[
OOWeakSet class]])
116 while ((
object = [selfEnum nextObject])) {
117 if (![other containsObject:
object]) {
132 return [_objects count];
135- (BOOL)containsObject:(
id<OOWeakReferenceSupport>)object
139 BOOL result = [_objects containsObject:weakObj];
149- (void)addObject:(
id<OOWeakReferenceSupport>)object
153 NSAssert([
object conformsToProtocol:
@protocol(OOWeakReferenceSupport)],
@"Attempt to add object to OOWeakSet which does not conform to OOWeakReferenceSupport.");
156 [_objects addObject:weakObj];
160- (void)removeObject:(
id<OOWeakReferenceSupport>)object
163 [_objects removeObject:weakObj];
167- (void)addObjectsByEnumerating:(NSEnumerator*)enumerator
171 while ((
object = [enumerator nextObject])) {
176- (void)makeObjectsPerformSelector:(
SEL)selector
184- (void)makeObjectsPerformSelector:(
SEL)selector withObject:(
id)argument
194 NSMutableArray* result = [
NSMutableArray arrayWithCapacity:[_objects count]];
205 return [
NSArray arrayWithArray:result];
211 [_objects removeAllObjects];
217 BOOL compactRequired = NO;
218 foreach (weakRef, _objects) {
219 if ([weakRef weakRefUnderlyingObject] ==
nil) {
220 compactRequired = YES;
225 if (compactRequired) {
227 foreach (weakRef, _objects) {
228 if ([weakRef weakRefUnderlyingObject] !=
nil) {
234 _objects = newObjects;
242- (id)initWithEnumerator:(NSEnumerator*)enumerator
244 if (enumerator ==
nil) {
249 if ((
self = [super init])) {
256+ (instancetype)enumeratorWithCollection:(
id)collection
258 return [[[
self alloc] initWithEnumerator:[
collection objectEnumerator]] autorelease];
272 next = [
next weakRefUnderlyingObject];
instancetype enumeratorWithCollection:(id collection)
NSEnumerator * _enumerator
id weakRefUnderlyingObject()
id copyWithZone:(NSZone *zone)
void addObject:(id< OOWeakReferenceSupport > object)
NSEnumerator * objectEnumerator()
void addObjectsByEnumerating:(NSEnumerator *enumerator)
id initWithCapacity:(NSUInteger capacity)