Open robb opened 12 years ago
An introduction of NSSet seems to be at odds with a unified iterator style for arrays and dictionaries
typedef void (^UnderscoreIteratorBlock)(id key, id obj);
typedef id (^UnderscoreMapBlock)(id key, id obj);
where, in the case of an NSArray
, key
would be the objects index in the array as an NSNumber
.
See #16
The more I think about it, the less inclined I am to add support for NSSet. It occurs only 64 times in method signatures on iOS 5.1 but some of those are quite useful
// CoreData.framework/Headers/NSAtomicStore.h
- (NSSet *)cacheNodes;
- (void)addCacheNodes:(NSSet *)cacheNodes;
- (void)willRemoveCacheNodes:(NSSet *)cacheNodes;
// CoreData.framework/Headers/NSManagedObject.h
- (void)willChangeValueForKey:(NSString *)inKey withSetMutation:(NSKeyValueSetMutationKind)inMutationKind usingObjects:(NSSet *)inObjects;
- (void)didChangeValueForKey:(NSString *)inKey withSetMutation:(NSKeyValueSetMutationKind)inMutationKind usingObjects:(NSSet *)inObjects;
// CoreData.framework/Headers/NSManagedObjectContext.h:
- (NSSet *)insertedObjects;
- (NSSet *)updatedObjects;
- (NSSet *)deletedObjects;
- (NSSet *)registeredObjects;
// CoreData.framework/Headers/NSManagedObjectModel.h
- (NSSet *)versionIdentifiers NS_AVAILABLE(10_5,3_0);
- (void)setVersionIdentifiers:(NSSet *)identifiers NS_AVAILABLE(10_5,3_0);
// CoreData.framework/Headers/NSSaveChangesRequest.h
- (id)initWithInsertedObjects:(NSSet*)insertedObjects updatedObjects:(NSSet*)updatedObjects deletedObjects:(NSSet*)deletedObjects lockedObjects:(NSSet*)lockedObjects;
- (NSSet *)insertedObjects;
- (NSSet *)updatedObjects;
- (NSSet *)deletedObjects;
- (NSSet *)lockedObjects;
// CoreMIDI.framework/Headers/MIDINetworkSession.h
- (NSSet *)contacts; /* elements MIDINetworkHost. */
- (NSSet *)connections; /* elements are MIDINetworkConnection. */
// Foundation.framework/Headers/NSDictionary.h
- (NSSet *)keysOfEntriesPassingTest:(BOOL (^)(id key, id obj, BOOL *stop))predicate NS_AVAILABLE(10_6, 4_0);
- (NSSet *)keysOfEntriesWithOptions:(NSEnumerationOptions)opts passingTest:(BOOL (^)(id key, id obj, BOOL *stop))predicate NS_AVAILABLE(10_6, 4_0);
// Foundation.framework/Headers/NSKeyValueObserving.h
- (void)willChangeValueForKey:(NSString *)key withSetMutation:(NSKeyValueSetMutationKind)mutationKind usingObjects:(NSSet *)objects;
- (void)didChangeValueForKey:(NSString *)key withSetMutation:(NSKeyValueSetMutationKind)mutationKind usingObjects:(NSSet *)objects;
// Foundation.framework/Headers/NSOrderedSet.h
- (BOOL)intersectsSet:(NSSet *)set;
- (BOOL)isSubsetOfSet:(NSSet *)set;
- (NSSet *)set;
- (id)initWithSet:(NSSet *)set;
- (id)initWithSet:(NSSet *)set copyItems:(BOOL)flag;
- (void)intersectSet:(NSSet *)other;
- (void)minusSet:(NSSet *)other;
- (void)unionSet:(NSSet *)other;
// Foundation.framework/Headers/NSPredicate.h
- (NSSet *)filteredSetUsingPredicate:(NSPredicate *)predicate NS_AVAILABLE(10_5, 3_0); // evaluate a predicate against a set of objects and return a filtered set
// Foundation.framework/Headers/NSSet.h
- (BOOL)intersectsSet:(NSSet *)otherSet;
- (BOOL)isEqualToSet:(NSSet *)otherSet;
- (BOOL)isSubsetOfSet:(NSSet *)otherSet;
- (NSSet *)setByAddingObject:(id)anObject NS_AVAILABLE(10_5, 2_0);
- (NSSet *)setByAddingObjectsFromSet:(NSSet *)other NS_AVAILABLE(10_5, 2_0);
- (NSSet *)setByAddingObjectsFromArray:(NSArray *)other NS_AVAILABLE(10_5, 2_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);
- (id)initWithSet:(NSSet *)set;
- (id)initWithSet:(NSSet *)set copyItems:(BOOL)flag;
- (void)intersectSet:(NSSet *)otherSet;
- (void)minusSet:(NSSet *)otherSet;
- (void)unionSet:(NSSet *)otherSet;
- (void)setSet:(NSSet *)otherSet;
- (id)initWithSet:(NSSet *)set;
// MapKit.framework/Headers/MKMapView.h
- (NSSet *)annotationsInMapRect:(MKMapRect)mapRect NS_AVAILABLE(NA, 4_2);
// MediaPlayer.framework/Headers/MPMediaEntity.h
- (void)enumerateValuesForProperties:(NSSet *)properties usingBlock:(void (^)(NSString *property, id value, BOOL *stop))block NS_AVAILABLE_IPHONE(4_0);
// MediaPlayer.framework/Headers/MPMediaQuery.h
- (id)initWithFilterPredicates:(NSSet *)filterPredicates;
// StoreKit.framework/Headers/SKProductsRequest.h
- (id)initWithProductIdentifiers:(NSSet *)productIdentifiers __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);
// UIKit.framework/Headers/UIControl.h
- (NSSet *)allTargets; // set may include NSNull to indicate at least one nil target
// UIKit.framework/Headers/UIEvent.h
- (NSSet *)allTouches;
- (NSSet *)touchesForWindow:(UIWindow *)window;
- (NSSet *)touchesForView:(UIView *)view;
- (NSSet *)touchesForGestureRecognizer:(UIGestureRecognizer *)gesture __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_2);
// UIKit.framework/Headers/UIGestureRecognizerSubclass.h
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
// UIKit.framework/Headers/UIResponder.h
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
// UIKit.framework/Headers/UIScrollView.h
- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view;
How about just support for uniq-ing an NSArray?
My concern is interfacing with methods that take or return NSSets, mostly the CoreData stuff where Underscore.m would probably be most useful.
Either way, uniq
sounds like a good addition to the Array methods, I'll open an issue
I'd like NSSet support! Use them very frequently.
Even though NSSet is not very popular, I feel we should at least investigate inclusion in Underscore.m.