People have expressed their desire for greater functionality from NSSet. Anyone who wants to write a few of the methods (or improve existing methods) should feel more than welcome.
At least one person has said they want:
*- (NSSet *)intersectionWithSet:(NSSet *)aSet; *- (NSSet *)setByAddingSet:(NSSet *)aSet; *- (NSSet *)setByRemovingSet:(NSSet *)aSet; *- (NSSet *)setByAddingObject:(id)anObject; *- (NSSet *)setByRemovingObject:(id)anObject;
NSSet category CocoaDevUsersAdditions:
NSSet+CocoaDevUsersAdditions.h
#import <Foundation/Foundation.h>
@interface NSSet (CocoaDevUsersAdditions)
// NOTE: results set contains instance of NSNull if result of performing selector with some object is nil
@end
NSSet+CocoaDevUsersAdditions.m
#import “NSSet+CocoaDevUsersAdditions.h”
@implementation NSSet (CocoaDevUsersAdditions)
(NSSet *)resultsOfMakeObjectsPerformSelector:(SEL)aSelector { NSMutableSet *result = [NSMutableSet set]; NSEnumerator *objectEnumerator; id obj; id objResult;
if (aSelector == NULL) { [NSException raise:NSInvalidArgumentException format:@”aSelector cannot be NULL.”]; }
objectEnumerator = [self objectEnumerator]; while (obj = [objectEnumerator nextObject]) { objResult = [obj performSelector:aSelector]; if (objResult == nil) objResult = [NSNull null]; [result addObject:objResult]; }
return result; }
(NSSet *)resultsOfMakeObjectsPerformSelector:(SEL)aSelector withObject:(id)anObject { NSMutableSet *result = [NSMutableSet set]; NSEnumerator *objectEnumerator; id obj; id objResult;
if (aSelector == NULL) { [NSException raise:NSInvalidArgumentException format:@”aSelector cannot be NULL.”]; }
objectEnumerator = [self objectEnumerator]; while (obj = [objectEnumerator nextObject]) { objResult = [obj performSelector:aSelector withObject:anObject]; if (objResult == nil) objResult = [NSNull null]; [result addObject:objResult]; }
return result; } @end
[[Category:CocoaDevUsersAdditions