yapstudios / YapDatabase

YapDB is a collection/key/value store with a plugin architecture. It's built atop sqlite, for Swift & objective-c developers.
Other
3.35k stars 365 forks source link

How to sort objects in AutoConsolidateGroups? #425

Closed shebinkoshy closed 6 years ago

shebinkoshy commented 7 years ago

Consider below example,

@{
    @"bond movies": @[ <@"movies", @"abc123">,    // <NFMovie:Goldfinger>
                       <@"movies", @"wyz123"> ],  // <NFMovie:Tomorrow never dies>

    @"80s movies" : @[ <@"movies", @"def456"> ],  // <NFMovie:Pretty In Pink>

    @"sherlock movies": @[ <@"movies", @"dfx214">,    // <NFMovie:Detektiv Braun>
                       <@"movies", @"qcas214"> ],  // <NFMovie:Jighansa>
}
YapDatabaseViewMappings *mappings =
  [YapDatabaseViewMappings mappingsWithGroups:@[@"bond movies", @"sherlock movies" ]
                                         view:@"myDetectiveView"];

i use following code for consolidate these groups

[mappings setAutoConsolidateGroupsThreshold:INTMAX_MAX withName:@"oneSection"];

But how can i sort all movies in alphabetical order from consolidated group?

Current output @[ <@"movies", @"abc123">, <@"movies", @"wyz123">, <@"movies", @"dfx214">, <@"movies", @"qcas214"] // Goldfinger, Tomorrow never dies, Detektiv Braun, Jighansa

Expected output Sorted with movie name

@[ <@"movies", @"dfx214">, <@"movies", @"abc123">, <@"movies", @"qcas214">, <@"movies", @"wyz123">] // Detektiv Braun, Goldfinger, Jighansa, Tomorrow never dies

shebinkoshy commented 6 years ago

I have updated my group objects filtering way and created a single group. Sorted with movie name also

YapDatabaseViewGrouping *viewGrouping = [YapDatabaseViewGrouping withObjectBlock:^NSString *(YapDatabaseReadTransaction *transaction, NSString *collection, NSString *key, id object) {

NFMovie *movie = (NFMovie*)object; 
 if([movie isDetectiveMovieWithTransaction:transaction]) {
return @"detectiveMovies";
}
return nil;
}];

So i am closing now.