Search code examples
objective-cnsfetchedresultscontroller

coredata error because sectionNameKeyPath or grouping data at NSFetchedResultsController


2011-12-28 10:52:13.633 BadgerNew[663:707] CoreData: error: (NSFetchedResultsController) object <Business: 0x628c8e0> (entity: Business; id: 0x628c870 <x-coredata://8D661026-BBFA-4C41-B434-167800D925DD/Business/p88> ; data: {
    Aliases = "<relationship fault: 0x6219950 'Aliases'>";
    Bookmark = 0;
    Building = nil;
    City = "0x56531a0 <x-coredata://8D661026-BBFA-4C41-B434-167800D925DD/City/p1>";
    Distance = "104.6926812925746";
    Districts =     (
        "0x63bcb30 <x-coredata://8D661026-BBFA-4C41-B434-167800D925DD/District/p1>"
    );
    Email = nil;
    ID = 74318;
    Images = "<relationship fault: 0x621a130 'Images'>";
    InBuildingAddress = nil;
    LatitudeLongitude = "0x565c2e0 <x-coredata://8D661026-BBFA-4C41-B434-167800D925DD/LatitudeLongitude/p81>";
    Like = 0;
    OpeningHour = nil;
    Phones = "<relationship fault: 0x62196b0 'Phones'>";
    Price = 0;
    Promotions = "<relationship fault: 0x6219630 'Promotions'>";
    Rating = "0x565e800 <x-coredata://8D661026-BBFA-4C41-B434-167800D925DD/Rating/p81>";
    Reviews =     (
    );
    Street = "Jl. Duri Raya 73";
    Tags =     (
        "0x63c38b0 <x-coredata://8D661026-BBFA-4C41-B434-167800D925DD/Tag/p74>"
    );
    Tenants = "<relationship fault: 0x62194c0 'Tenants'>";
    TimeStamp = nil;
    Title = "Toko Guna Bangunan Jaya";
    URLs = "<relationship fault: 0x6219440 'URLs'>";
    Website = nil;
    Zip = 11510;
    pinAndLineNumber = 1;
    updated = 0;
}) returned nil value for section name key path 'Building.Title'. Object will be placed in unnamed section

this error log is appear when I want to grouping data at NSFetchedResultsController use sectionNameKeyPath:@"Building.Title". something like this

NSFetchedResultsController * FRC=[[[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:[ThreadClass managedObjectContext] sectionNameKeyPath:@"Building.Title" cacheName:Nil]autorelease];

anyone can help me to fix this with Building can be nil? because I want to show something like

enter image description here


Solution

  • I figured the answer out. If you group by building you must also sort by building or building location. The order of your sorting must match the order of your grouping. So you cannot have a situation where items on the same "group" to have separate ordering.