FunkySort

@interface FunkySort : NSObject

This is a collection of methods to provide comparator helpers

  • Provides a lexicographical comparator, so if the collection is sorted using this method, all the elements should be comparable using the -compare: method

    Declaration

    Objective-C

    + (NSComparator)lexicographicalComparator;

    Swift

    class func lexicographicalComparator() -> Comparator!

    Return Value

    A comparator to use when sorting collections

  • Provides a property comparator, mapping the current object into another comparable one which responds to the -compare: method. In case of a complex object you usually return a property of it which holds a primitive value, like NSString or NSNumber

    Declaration

    Objective-C

    + (NSComparator)propertyComparator:
        (FunkySortComparablePropertyProviderBlock)propertyBlock;

    Swift

    class func propertyComparator(_ propertyBlock: Any!) -> Comparator!

    Parameters

    propertyBlock

    The block to map the current element into a comparable one

    Return Value

    A comparator to use when sorting collections

  • Provides a special comparator for comparing objects, but when only interested in their asending or descending information. It is usually used when comparing numbers in an array, like return obj1 < obj2 to have an ascending collection

    See

    The type of block to can provide is FunkySortBoolComparableBlock

    Declaration

    Objective-C

    + (NSComparator)boolComparator:(FunkySortBoolComparableBlock)comparator;

    Swift

    class func boolComparator(_ comparator: Any!) -> Comparator!

    Parameters

    comparator

    The block to use when comparing two objects

    Return Value

    A comparator to use when sorting collections

  • A composite comparator, providing multiple comparators in it, so when based on one comparation the objects are equal, the next one is being used.

    Declaration

    Objective-C

    + (NSComparator)prioritizedComparator:(NSArray<NSComparator> *)comparators;

    Swift

    class func prioritizedComparator(_ comparators: [Comparator]!) -> Comparator!

    Parameters

    comparators

    The list of comparators to use in order

    Return Value

    A comparator to use when sorting collections

  • A composite comparator using buckets. It orders the list in a way, that it uses so called buckets which represent a subset of the elements. So the order is going to be made up of the order of these buckets. There is a special bucket, called collector bucket (-[FunkySortingBucket bucketWithAllTheRest]) which hold all the remaining element which couldn’t fit in any of the other concrete buckets. This collector bucket can be placed even in the middle of the list of buckets, so you can achieve to order a bucket at last. By default the collector is at the end. In this method the default inner bucket comparator is the lexicographical one.

    See

    The buckets to provide are FunkySortingBucket instances

    See

    Comparator with custom inner-bucket comparator +[FunkySort comparatorWithBuckets:defaultInnerBucketComparator:]

    Declaration

    Objective-C

    + (NSComparator)comparatorWithBuckets:(NSArray<FunkySortingBucket *> *)buckets;

    Swift

    class func comparator(withBuckets buckets: [Any]!) -> Comparator!

    Parameters

    buckets

    The list of buckets to use in order

    Return Value

    A comparator to use when sorting collections

  • Same as +[FunkySort comparatorWithBuckets:] but with an addition to set the default inner bucket comparator.

    See

    The buckets to provide are FunkySortingBucket instances

    See

    Comparator with the default lexicographical inner-bucket comparator +[FunkySort comparatorWithBuckets:]

    Declaration

    Objective-C

    + (NSComparator)comparatorWithBuckets:(NSArray<FunkySortingBucket *> *)buckets
             defaultInnerBucketComparator:
                 (NSComparator)defaultInnerBucketComparator;

    Swift

    class func comparator(withBuckets buckets: [Any]!, defaultInnerBucketComparator: Comparator!) -> Comparator!

    Parameters

    buckets

    The list of buckets to use in order

    defaultInnerBucketComparator

    The default comparator to use instead of the lexicographical one

    Return Value

    A comparator to use when sorting collections