20- (id) initWithEnumerator:(NSEnumerator *)enumerator;
22+ (instancetype) enumeratorWithCollection:(
id)collection;
27@interface OOWeakSet (OOPrivate)
42- (id) initWithCapacity:(NSUInteger)capacity
44 if ((
self = [super
init]))
42- (id) initWithCapacity:(NSUInteger)capacity {
…}
59 return [[[
self alloc] init] autorelease];
63+ (instancetype) setWithCapacity:(NSUInteger)capacity
65 return [[[
self alloc] initWithCapacity:capacity] autorelease];
63+ (instancetype) setWithCapacity:(NSUInteger)capacity {
…}
79 NSMutableString *result = [
NSMutableString stringWithFormat:@"<%@ %p>{", [
self class],
self];
83 while ((
object = [selfEnum nextObject]))
85 if (!first) [
result appendString:@", "];
89 if ([
object respondsToSelector:
@selector(shortDescription)]) desc = [
object shortDescription];
90 else desc = [
object description];
92 [
result appendString:desc];
95 [
result appendString:@"}"];
102- (id) copyWithZone:(NSZone *)zone
102- (id) copyWithZone:(NSZone *)zone {
…}
111- (id) mutableCopyWithZone:(NSZone *)zone
111- (id) mutableCopyWithZone:(NSZone *)zone {
…}
117- (BOOL) isEqual:(
id)other
119 if (![other isKindOfClass:[
OOWeakSet class]])
return NO;
126 while ((
object = [selfEnum nextObject]))
128 if (![other containsObject:
object])
117- (BOOL) isEqual:(
id)other {
…}
145 return [_objects count];
149- (BOOL) containsObject:(
id<OOWeakReferenceSupport>)object
153 BOOL result = [_objects containsObject:weakObj];
149- (BOOL) containsObject:(
id<OOWeakReferenceSupport>)object {
…}
165- (void) addObject:(
id<OOWeakReferenceSupport>)object
167 if (
object ==
nil)
return;
168 NSAssert([
object conformsToProtocol:
@protocol(OOWeakReferenceSupport)],
@"Attempt to add object to OOWeakSet which does not conform to OOWeakReferenceSupport.");
171 [_objects addObject:weakObj];
165- (void) addObject:(
id<OOWeakReferenceSupport>)object {
…}
176- (void) removeObject:(
id<OOWeakReferenceSupport>)object
179 [_objects removeObject:weakObj];
176- (void) removeObject:(
id<OOWeakReferenceSupport>)object {
…}
184- (void) addObjectsByEnumerating:(NSEnumerator *)enumerator
188 while ((
object = [enumerator nextObject]))
184- (void) addObjectsByEnumerating:(NSEnumerator *)enumerator {
…}
195- (void) makeObjectsPerformSelector:(
SEL)selector
195- (void) makeObjectsPerformSelector:(
SEL)selector {
…}
205- (void) makeObjectsPerformSelector:(
SEL)selector withObject:(
id)argument
205- (void) makeObjectsPerformSelector:(
SEL)selector withObject:(
id)argument {
…}
217 NSMutableArray *result = [
NSMutableArray arrayWithCapacity:[_objects count]];
228 return [
NSArray arrayWithArray:result];
235 [_objects removeAllObjects];
242 BOOL compactRequired = NO;
243 foreach (weakRef, _objects)
245 if ([weakRef weakRefUnderlyingObject] ==
nil)
247 compactRequired = YES;
255 foreach (weakRef, _objects)
257 if ([weakRef weakRefUnderlyingObject] !=
nil)
264 _objects = newObjects;
273- (id) initWithEnumerator:(NSEnumerator *)enumerator
275 if (enumerator ==
nil)
281 if ((
self = [super init]))
273- (id) initWithEnumerator:(NSEnumerator *)enumerator {
…}
290+ (instancetype) enumeratorWithCollection:(
id)collection
292 return [[[
self alloc] initWithEnumerator:[
collection objectEnumerator]] autorelease];
290+ (instancetype) enumeratorWithCollection:(
id)collection {
…}
309 next = [
next weakRefUnderlyingObject];
310 if (next !=
nil)
return next;
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)