Coredata error because sectionNameKeyPath or data grouping in 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 appears when I want to group data into an NSFetchedResultsController using sectionNameKeyPath: @ "Building.Title". something like that

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

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

enter image description here

+4
source share
2 answers

I understood the answer. If you are grouping, you must also sort by building or building location. The sort order should match the order of your grouping. Thus, you cannot have a situation where the elements of one group can have a separate order.

+4
source

The first thing you need to do is rename your relationships and attributes. I don’t know how, but usually attribute names and relationship names cannot begin with a capital letter. Typically, the model editor in Xcode provides this.

Now to your real problem:

There are, as always, several solutions. I am trying to explain one possible solution:

Make sure Building.Title is never zero: you can do this at the level of your controller or at the model level. If you do this at the model level, just subclass NSManagedObject for this object and create a new readonly property, which you can call "titleForDisplay". Before returning a Title value, just check to see if it is nil and if it replaces it with a localized string that represents nil values.

+3
source

Source: https://habr.com/ru/post/1388235/


All Articles