EXC_BREAKPOINT crash with "protocol witness for delegate.[method_name] in conformance"

Here is the related code where I get the crash:

protocol MixedItemsPerRowFlowLayoutDelegate: NSObjectProtocol {
    typealias TileType = SelfSizingCellProtocol & CellConfigurable

    func tileAtIndexPath(_ indexPath: IndexPath) -> TileType?
    func estimatedItemsPerRow() -> Int

class MixedItemsPerRowFlowLayout {
    weak var flowLayoutDelegate: MixedItemsPerRowFlowLayoutDelegate?

   func itemWidth(atIndexPath indexPath: IndexPath?) -> CGFloat {
       if let delegate = self.flowLayoutDelegate, let indexPath = indexPath, let tile = delegate.tileAtIndexPath(indexPath) {

This is a UICollectionViewLayout subclass. The MixedItemsPerRowFlowLayoutDelegate is a ViewController. The crash happens on the tileAtIndexPath call: protocol witness for MixedItemsPerRowFlowLayoutDelegate.tileAtIndexPath(_:). in conformance ViewController. Any ideas on what's going on? Unfortunately we're unable to reproduce, but see a bunch of instances in our crash logs.

Is there any integer arithmetic in your implementation that might be overflowing?

This is the implementation:

func tileAtIndexPath(_ indexPath: IndexPath) -> MixedItemsPerRowFlowLayoutDelegate.TileType? {
    return self.viewModel.tiles[indexPath.item]

Could it be that indexPath.item is out of bounds of the array?

That seems like a likely cause of the trap, yeah.

Terms of Service

Privacy Policy

Cookie Policy