Skip to content
This repository was archived by the owner on Nov 12, 2024. It is now read-only.

Repository files navigation

SHFastEnumerationProtocols

CI StatusVersionPlatformLicense

This pod is used by SHFoundationAdditions as part of several components improving Foundation, UIKit, CoreLocation, GameKit, MapKit and other aspects of an iOS application's architecture.

Overview

NSFastEnumeration helpers and enumeration blocks through a protocol on foundation collection classes. Helpers for both keyed, index and unordered collection objects. Converting to other collection classes through dot notation. Block based callers for enumeration. Tested and ready.

  • NSArray and NSMutableArray
  • NSOrderedSet and NSMutableOrderedSet
  • NSSet, NSMutableSet and NSCountedset
  • NSHashTable
  • NSDictionary and NSMutableDictionary
  • NSMapTable

TODO: NSIndexSet, NSMutableIndexSet and NSEnumerator.

TODO: Keyed protocols

API

Installation

pod'SHFastEnumerationProtocols'

Setup

Put this either in specific files or your project prefix file

#import"<CollectionClass>+SHFastEnumerationProtocols.h"

or for all classes

#import"SHFastEnumerationProtocols.h"

API

#pragma mark - Block Definitions
//obj is the key for keyed indexed classes (NSDictionary, NSMapTable)typedefvoid (^SHIteratorBlock)(id obj);
typedefvoid (^SHIteratorWithIndexBlock)(id obj, NSInteger index) ;
typedefid (^SHIteratorReturnIdBlock)(id obj);
typedefid (^SHIteratorReduceBlock)(id memo, id obj);
typedefBOOL (^SHIteratorPredicateBlock)(id obj);
#pragma mark - <SHFastEnumerationBlocks>
@protocolSHFastEnumerationBlocks <NSObject>
@required//obj is the key for keyed indexed classes (NSDictionary, NSMapTable)
-(void)SH_each:(SHIteratorBlock)theBlock;
//the loop is on HIGH queue, each iteration on BACKGROUND, completion callback is on main
-(void)SH_concurrentEach:(SHIteratorBlock)theBlockonComplete:(SHIteratorBlock)theCompleteBlock;
//Collect
-(instancetype)SH_map:(SHIteratorReturnIdBlock)theBlock;
//Inject/FoldLeft
-(id)SH_reduceValue:(id)theValuewithBlock:(SHIteratorReduceBlock)theBlock;
//Match
-(id)SH_find:(SHIteratorPredicateBlock)theBlock;
//Select/Filter
-(instancetype)SH_findAll:(SHIteratorPredicateBlock)theBlock;
//!Select/Filter
-(instancetype)SH_reject:(SHIteratorPredicateBlock)theBlock;
//Every
-(BOOL)SH_all:(SHIteratorPredicateBlock)theBlock;
//Some
-(BOOL)SH_any:(SHIteratorPredicateBlock)theBlock;
// !Every
-(BOOL)SH_none:(SHIteratorPredicateBlock)theBlock;
@end
#pragma mark - <SHFastEnumerationProperties>
@protocolSHFastEnumerationProperties <NSObject>
@required@property(nonatomic,readonly) BOOL SH_hasObjects;
@property(nonatomic,readonly) NSArray * SH_toArray;
@property(nonatomic,readonly) NSSet * SH_toSet;
@property(nonatomic,readonly) NSOrderedSet * SH_toOrderedSet;
//The objects are the values while the key will either be an NSNumber index (from ordered)//or a counted key (unordereD)@property(nonatomic,readonly) NSDictionary * SH_toDictionary;
@property(nonatomic,readonly) NSMapTable * SH_toMapTableWeakToWeak;
@property(nonatomic,readonly) NSMapTable * SH_toMapTableWeakToStrong;
@property(nonatomic,readonly) NSMapTable * SH_toMapTableStrongToStrong;
@property(nonatomic,readonly) NSMapTable * SH_toMapTableStrongToWeak;
@property(nonatomic,readonly) NSHashTable * SH_toHashTableWeak;
@property(nonatomic,readonly) NSHashTable * SH_toHashTableStrong;
//https://gist.github.com/seivan/6086183@property(nonatomic,readonly) NSDecimalNumber * SH_collectionAvg;
@property(nonatomic,readonly) NSDecimalNumber * SH_collectionSum;
@property(nonatomic,readonly) id SH_collectionMax;
@property(nonatomic,readonly) id SH_collectionMin;
@end
#pragma mark - <SHFastEnumerationOrderedBlocks>
@protocolSHFastEnumerationOrderedBlocks <NSObject>
@required
-(void)SH_eachWithIndex:(SHIteratorWithIndexBlock)theBlock;
@end
#pragma mark - <SHFastEnumerationOrderedProperties>
@protocolSHFastEnumerationOrderedProperties <NSObject>
@required@property(nonatomic,readonly) id SH_firstObject;
@property(nonatomic,readonly) id SH_lastObject;
@end
#pragma mark - <SHFastEnumerationOrdered>
@protocolSHFastEnumerationOrdered <NSObject>
@required
-(instancetype)SH_reverse;
-(id)SH_objectBeforeObject:(id)theObject;
-(id)SH_objectAfterObject:(id)theObject;
@end
#pragma mark - <SHMutableFastEnumerationBlocks>
@protocolSHMutableFastEnumerationBlocks <NSObject>
@required
-(void)SH_modifyMap:(SHIteratorReturnIdBlock)theBlock;
-(void)SH_modifyFindAll:(SHIteratorPredicateBlock)theBlock;
-(void)SH_modifyReject:(SHIteratorPredicateBlock)theBlock;
@end
#pragma mark - <SHMutableFastEnumerationOrdered>
@protocolSHMutableFastEnumerationOrdered <NSObject>
@required
-(void)SH_modifyReverse;
-(id)SH_popObjectAtIndex:(NSInteger)theIndex;
-(id)SH_popFirstObject;
-(id)SH_popLastObject;
@end

Contact

If you end up using SHFastEnumerationProtocols in a project, I'd love to hear about it.

email: seivan.heidari@icloud.com
twitter: @seivanheidari

License

SHFastEnumerationProtocols is © 2013 Seivan and may be freely distributed under the MIT license. See the LICENSE.md file.

About

Block Enumerables and convenience helpers on all the NSFastEnumeration collection classes.

Resources

Stars

10 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages