TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2014 |
Maintained by Sam Dods.
The aim of this project is to tackle the disadvantages of KVC Collection Operators
The obvious advatange is clarity in consicion.
But I also want the following:
All macros intended for public use have the format:
MacroName(collection, typeOfObjectsInCollection, keyPath)
NSArray *
, NSSet *
, etc. e.g. self.transactions
Transaction *
- I chose to require the full type including asterisk in order to be explicitpayee.name
... with the exception of the "Added Convenience" macros for collections of NSNumber *
s, see below.
I can create an array of all the names of payees for transactions, as follows:
NSArray *payeeNames = DZLUnionOfObjects(self.transactions, Transaction *, payee.name);
@avg
@count
@sum
@min
with added compile-time validation that objects in the collection respond to -compare
@max
with added compile-time validation that objects in the collection respond to -compare
NSNumber *
NSNumber *
double
or compatible scalar typedouble
or compatible scalar typeNSNumber *
objects -- and returns the averageNSNumber *
objects -- and returns the sum@distinctUnionOfObjects
@unionOfObjects
@distinctUnionOfArrays
@unionOfArrays
@distinctUnionOfSets
You can get the average of a collection of numbers using the macros above as follows:
NSNumber *average = DZLAverage(numbers, NSNumber *, self);
I've added the convenience methods for this and for sum, which can be used as follows:
NSNumber *average = DZLAverageOfNumbers(numbers);
NSNumber *sum = DZLSumOfNumbers(numbers);
Use CocoaPods, or simply add DZLCollectionOperators.h file to your project.
It's as simple as that, it's just a header file with macros!
If you like this, you can follow me on twitter for more of the same!