What is the best way to fetch multiple Core Data entity types for presentation together in a collection?

I have three core data entity types which are subclasses of a shared parent class, but which do not inherit from a shared parent entity type in Core Data. Let's call the three types businesses, customers, and products. Every entity type has the possibility of many-to-many relationships with each of the other entity types. e.g., a business could have relationships with multiple other businesses, customers, and products. A product could be sold by multiple businesses and have been purchased by multiple customers, and be related to other products. These are Core Data many-to-many relationships.

There are two contexts in which I am presenting these entities: as results from a search, and to display the other entities that are in relationship with a specific entity that the user has selected. Currently, I have implemented both of these contexts as being entity-type specific—at any one time you search for products, or businesses, or customers. You change to a different scope within a UISearchBar to swap between entity types. Likewise, when viewing details of a specific entity, you can view lists of the items related to that entity separately for each of the three types. Results are fetched with an NSFetchResultsController in both cases, with an appropriate predicate. Some users have 10,000 entities in total across the categories. Few or none will have 100,000.

I want to present collections that instead intermix items from all three of these types in the displayed results or lists.

As far as I am aware, this is not possible with an NSFetchedResultsController unless I redesigned my Core Data model to have them all inherit from a base entity type, and that seems to have significant downsides on an ongoing basis, in addition to the necessary complex migration.

What is the best way to achieve this? I am open to any technology, any approach, and am willing to raise the required iOS version to iOS 13 or even iOS 14 in order to be able to use the most ideal approach.

Replies

An addendum. The two use cases outlined above are:
  • to be able to return entities of any of the types that have properties that meet a particular search term, and

  • to display the other entities that are in relationship with a selected entity.

In the latter case, one particular thing I want to do is to present a chronological timeline of the entity relationships to other entities that have been added or changed over time, e.g., this customer is now in a relationship with this business, or with this product, as a single unified timeline. What I'm starting to think is that the way to do this is perhaps to create an intermediate entity of some kind, e.g., a timelineEvent entity, which is created at the point of creating a relationship between two of my existing entities. These lightweight entities would not be used to manage the relationship between the entities, but would be used to provide a history about those events. Thus, displaying a timeline of those events could be via an NSFetchedResultsController that is fetching only a single entity type, timelineEvent, and then from that creating one of a range of collection view items depending on the type of entity the relationship was with. Is this a good approach to the problem I'm outlining?

In other cases, it likely makes sense for my use case to just continue to fetch each of the entities via the relationship, on a per-entity-type basis, and then display those as individual collections of entities, rather than trying to intermix them. But I am most interested in any feedback or suggestions. :)