问题
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
回答1:
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.
回答2:
The first thing you should do is to rename your relationships and attributes. I don't know how but usually attribute names and relationship names cannot start with a big letter. Usually the model editor in Xcode enforces this.
Now to your actual problem:
There are, as always, more than one solution. I try to explain one possible solution:
Make sure that Building.Title is never nil: You can do this in your controller layer or in your model layer. If you do it in the model layer simply create a subclass of NSManagedObject for this entity and create a new readonly property that you may call "titleForDisplay". Before returning the value of Title simply check if its nil and if so replace it with a localized string that represents nil values.
来源:https://stackoverflow.com/questions/8651702/coredata-error-because-sectionnamekeypath-or-grouping-data-at-nsfetchedresultsco