YapDatabaseViewGrouping

@interface YapDatabaseViewGrouping : NSObject

The grouping block handles both filtering and grouping.

When you add or update rows in the database the grouping block is invoked. Your grouping block can inspect the row and determine if it should be a part of the view. If not, your grouping block simply returns ‘nil’ and the object is excluded from the view (removing it if needed). Otherwise your grouping block returns a group, which can be any string you want. Once the view knows what group the row belongs to, it will then determine the position of the row within the group (using the sorting block).

It is recommended you choose a block type that takes the minimum number of required parameters. This allows the view to make various optimizations based on the required parameters of the block.

If you’d like to get more advanced, you can specify exactly what should trigger an invocation of the block. For example:

If you use a ‘GroupingWithObjectBlock’, then normally the view will assume that any changes to the ‘object’ in the database means that the groupingBlock should be re-invoked (to check for changes to the group). However, your groupingBlock may be more static than that. That is, it may simply be based on an immutable property of the object. And as such, it only needs to be run once (because the group will never change). So you can use the ‘options’ parameter to specify YapDatabaseBlockInvokeOnInsertOnly. This will allow the view to properly optimize based on the details of your actual groupingBlock implementation.