What does "Cannot solve for a non-group item." mean?

I'm using a UICollectionViewCompositionalLayout, and an exception is thrown when I load my collection view.

The exception says "Cannot solve for a non-group item."


Any idea what might be wrong? Or how to fix it?


Here's my layout code

func sideBarSectionCollectionLayout()->UICollectionViewCompositionalLayout {
  let size = NSCollectionLayoutSize(widthDimension:.fractionalWidth(1), heightDimension:.estimated(105))
  let item = NSCollectionLayoutItem(layoutSize: size)
  let group = NSCollectionLayoutGroup.horizontal(layoutSize: size, subitems: [item])

  let section = NSCollectionLayoutSection(group: group)
  section.contentInsets = NSDirectionalEdgeInsets(top: 5, leading: 5, bottom: 5, trailing: 5)
  section.interGroupSpacing = 5

  return UICollectionViewCompositionalLayout(section: section)
  }


My cells are set up in the storyboard.


I'm running xcode 11.1 (11A1027), and catalina 10.15.1 Beta (19B68f)


It started after the catalina upgrade from the GM.


Here's the relevant part of the stack trace.

2019-10-17 04:02:04.556019-0400 SingAccord[4897:254625] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Cannot solve for a non-group item.'
*** First throw call stack:
(
  0   CoreFoundation                      0x00007fff3ab7ff43 __exceptionPreprocess + 250
  1   libobjc.A.dylib                     0x00007fff70d23835 objc_exception_throw + 48
  2   CoreFoundation                      0x00007fff3ab9b800 +[NSException raise:format:arguments:] + 88
  3   Foundation                          0x00007fff3d27a5d1 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
  4   UIKitCore                           0x00007fff78be85db -[_UICollectionLayoutItemSolver _solveGroup] + 3778
  5   UIKitCore                           0x00007fff78be7054 -[_UICollectionLayoutItemSolver _solveForContainer:layoutAxis:traitCollection:maxFrameCount:layoutRTL:preferredSizes:solutionRecursionDepth:] + 253
  6   UIKitCore                           0x00007fff78be59ac -[_UICollectionLayoutItemSolver solveForContainer:layoutAxis:traitCollection:maxFrameCount:layoutRTL:preferredSizes:] + 110
  7   UIKitCore                           0x00007fff78bf400b __66-[_UICollectionLayoutSectionEstimatedSolver _solveWithParameters:]_block_invoke.195 + 243
  8   UIKitCore                           0x00007fff78bf24c6 -[_UICollectionLayoutSectionEstimatedSolver _solveWithParameters:] + 2812
  9   UIKitCore                           0x00007fff78befc94 -[_UICollectionLayoutSectionEstimatedSolver solveForContainer:traitCollection:layoutAxis:frameCount:preferredSizes:layoutRTL:] + 284
  10  UIKitCore                           0x00007fff78bcdf77 -[_UICollectionCompositionalLayoutSolver _solveWithSectionLayouts:preferredSizesDict:dataSourceSnapshot:update:] + 1491
  11  UIKitCore                           0x00007fff78bcd98d -[_UICollectionCompositionalLayoutSolver _solve] + 201
  12  UIKitCore                           0x00007fff78bc42a1 -[_UICollectionCompositionalLayoutSolver initWithContainer:traitCollection:layoutAxis:dataSourceSnapshot:options:sectionProvider:] + 659
  13  UIKitCore                           0x00007fff78bbff99 -[UICollectionViewCompositionalLayout _fullResolve] + 1216
  14  UIKitCore                           0x00007fff78bbec6b -[UICollectionViewCompositionalLayout invalidateLayoutWithContext:] + 1387
  15  UIKitCore                           0x00007fff788238bb -[UICollectionViewLayout _invalidateLayoutUsingContext:] + 56
  16  UIKitCore                           0x00007fff788237cf -[UICollectionView _invalidateLayoutIfNecessaryForReload] + 155
  17  UIKitCore                           0x00007fff7882a031 -[UICollectionView reloadData] + 977
  18  UIKit                               0x00007fff723af328 -[UICollectionViewAccessibility reloadData] + 42

Replies

I wonder how the group manages the .estimated.


Could you test with .absolute instead of estimated ?


For another test, could you change the call

from

  let group = NSCollectionLayoutGroup.horizontal(layoutSize: size, subitems: [item])


to


  let group = NSCollectionLayoutGroup.horizontal(layoutSize: size, subitem: item, count: 1)



Did you read this:

h ttps://dev.to/kevinmaarek/using-collectionview-compositional-layouts-in-swift-5-1nan


and more important :

https://developer.apple.com/videos/play/wwdc2019/215/

Well, I need the group to grow based on the size of the cell, so absolute sizes aren't an option for me here in this design.


I ran it in the iPad OS 13.1 Simulator, and it worked fine. And it worked fine many many times before I upgraded to the beta. So I'm guessing it's a new bug that's worked its way into the catalina beta (I'm downloading beta 2 of 10.15.1 now).

Upgrading to beta 2 didn't help, but it still works fine in the ipad os 13.2 simulator. I'm reporting this as a bug.

I had such big hopes for macCatalyst and UICollectionViewCompositionalLayout, but on a weekly basis I can't practically get any work done for the internal crashing bugs.

Also works fine on an iPad Pro running os 13, so it's gotta be a bug somehow related to macCatalyst.

Thanks for the feedback.


Did you file a bug report ?

Yes, I filed a bug report in Feedback Assistant.

I also downgraded my mac os from the beta to the non-beta version and the exceptions aren't thrown anymore, and my layout looks like I'd expect, and what it looked like before the beta upgrade, and the same as it does on a real iPad. I hope they fix the bug before the next release!

This bug is now in Catalina public release of 10.15.1 and I'm no longer able to use UICollectionViews in Mac Catalyst.

I can no longer develop my MacCatalyst app.


Come on Apple.

Same problem here. The bug is reproduced with apple's own demo project for compositional layout (if you enable catalyst for the UIKit demo and run on mac) - https://developer.apple.com/documentation/uikit/views_and_controls/collection_views/using_collection_view_compositional_layouts_and_diffable_data_sources

Seems fixed in the latest Catalina 15.2 beta 4 (19C56a).