App built with Xcode 16 crashes, worked fine with Xcode 15

I'm not a developer, so my knowledge is limited. I only know enough to update the content of my app from time to time using Xcode. The app is database driven and includes hundreds of photos. It has worked fine for years and has never crashed. However, after I updated Xcode to 16.1 my app crashes when I run it on an iOS 18 Simulator. (It works fine on an iOS 17 Simulator.) The problem seems to have something to do with UItableView. Before I spend a lot of $$ for a developer to look into this, I'm wondering if the crashes might be because of a bug that will be fixed in future. Is there any way to tell? I have the crash report, but it's very long so I won't post it unless asked to. If it's helpful, this is the section of code that crashes:

// MARK: UITableViewDataSource extension DetailCollectionViewCell: UITableViewDataSource {

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    guard let tableViewData = tableViewData else { fatalError("no tableViewData") } **Thread 1: fatal error: No tableViewData**

    return tableViewData.count
Answered by Claude31 in 817298022

Most probably, it is an error in your code. Problem comes likely from how tableViewData was declared.

Where and how did you define

  • DetailCollectionViewCell
  • tableViewData ?: was it declared as private var ? It should not. How was it initialised ? May be too late and not yet when tableView is called.

That could explain the error in iOS 18: you may have made wrong assumptions on the fact that tableViewData would exist at the time tableView function is called. It did work in iOS 17, because system happily let enough time to initialise. But no more in iOS 18 (optimised, or just changed).

But that would not be a bug in iOS.

Please show more code. It is hard to tell otherwise.

And show the part of the crash report dealing with thread 1.

Accepted Answer

Most probably, it is an error in your code. Problem comes likely from how tableViewData was declared.

Where and how did you define

  • DetailCollectionViewCell
  • tableViewData ?: was it declared as private var ? It should not. How was it initialised ? May be too late and not yet when tableView is called.

That could explain the error in iOS 18: you may have made wrong assumptions on the fact that tableViewData would exist at the time tableView function is called. It did work in iOS 17, because system happily let enough time to initialise. But no more in iOS 18 (optimised, or just changed).

But that would not be a bug in iOS.

Please show more code. It is hard to tell otherwise.

And show the part of the crash report dealing with thread 1.

Claude, thank you for your quick and detailed reply. I don't know much about code, but here is what I think might be the relevant section.

// // DetailCollectionViewCell.swift // SulawesiFishIDApp2024 // // Created by Geoff Hackworth on 06/01/2017. // Copyright © 2019 John Hoover. All rights reserved. //

import UIKit

protocol DetailCollectionViewCellDelegate: AnyObject { func detailCollectionViewCell(_ detailCollectionViewCell: DetailCollectionViewCell, didSelectImageAt index: Int)

func detailCollectionViewCellDidSelectReefDistributionReport(_ detailCollectionViewCell: DetailCollectionViewCell)
func detailCollectionViewCellDidSelectFishbase(_ detailCollectionViewCell: DetailCollectionViewCell)

}

final class DetailCollectionViewCell: UICollectionViewCell {

weak var delegate: DetailCollectionViewCellDelegate?

@IBOutlet fileprivate weak var tableView: UITableView!

var tableViewContentInset: UIEdgeInsets = .zero {
    didSet {
        tableView.contentInset = tableViewContentInset
    }
}

struct ViewData {
    let commonName: String
    let isEndemic: Bool
    let isFamilyId: Bool
    let lengthDescription: String?
    let scientificName: String?
    let scientificFamily: String?
    let familyText: String?
    let rank: String?
    let reefReportGroupId: String?
    let fishbaseLinkId: String
    let upperImages: [UIImage]
    let lowerImages: [UIImage]
    let description: String
}

And here is the section of the crash report. It says Thread 0 crashed, not Thread 1.

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 libswiftCore.dylib 0x19481539c assertionFailure(::file:line🎏 ) + 244 1 SulawesiFishIDApp2024.debug.dylib 0x10135078c DetailCollectionViewCell.tableView(:numberOfRowsInSection:) + 312 (DetailCollectionViewCell.swift:207) 2 SulawesiFishIDApp2024.debug.dylib 0x1013507cc @objc DetailCollectionViewCell.tableView(_:numberOfRowsInSection:) + 60 3 UIKitCore 0x185d38468 -[UITableView _numberOfRowsInSection:] + 48 4 UIKitCore 0x185d4c06c -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 1772 5 UIKitCore 0x185d50634 -[UITableViewRowData rectForFooterInSection:heightCanBeGuessed:] + 100 6 UIKitCore 0x185d50f0c -[UITableViewRowData heightForTable] + 48 7 UIKitCore 0x185cfb730 -[UITableView _updateContentSizeSkippingContentOffsetAdjustment:] + 164 8 UIKitCore 0x185d1fe78 -[UITableView _rebuildGeometryForcingRowDataUpdate:skipContentOffsetAdjustment:updateImmediatelyIfPossible:] + 136 9 UIKitCore 0x185d1e2a8 -[UITableView setLayoutMargins:] + 200 10 UIKitCore 0x185d1e1c4 -[UITableView _setDefaultLayoutMargins:] + 48 11 UIKitCore 0x185d1e134 -[UITableView didMoveToWindow] + 284 12 UIKitCore 0x18603ef14 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1868 13 UIKitCore 0x185fc5d1c -[UIScrollView _didMoveFromWindow:toWindow:] + 84 14 UIKitCore 0x18603ea8c -[UIView(Internal) _didMoveFromWindow:toWindow:] + 708 15 UIKitCore 0x18603ea8c -[UIView(Internal) _didMoveFromWindow:toWindow:] + 708 16 UIKitCore 0x186034720 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 124 17 UIKitCore 0x186034634 -[UIView _postMovedFromSuperview:] + 436 18 UIKitCore 0x186040ee8 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 2204 19 UIKitCore 0x1851d0bb8 -[UICollectionView _addSubview:positioned:relativeTo:] + 144 20 UIKitCore 0x185cccaa0 -[_UICollectionViewSubviewRouter addControlledSubview:zIndex:orderMode:] + 816 21 UIKitCore 0x1851d06f0 -[UICollectionView _addControlledSubview:atZIndex:forced:initialAttributes:] + 328 22 UIKitCore 0x1851d69c0 -[UICollectionView _applyLayoutAttributes:toView:addingControlledSubview:forced:] + 144 23 UIKitCore 0x1851eb70c __88-[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:]block_invoke_2 + 108 24 UIKitCore 0x18603b5a0 +[UIView(Animation) performWithoutAnimation:] + 68 25 UIKitCore 0x1851eb388 -[UICollectionView dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:] + 1332 26 UIKitCore 0x1851eb7e0 -[UICollectionView dequeueReusableCellWithReuseIdentifier:forIndexPath:] + 80 27 SulawesiFishIDApp2024.debug.dylib 0x101354b1c UICollectionView.dequeueReusableCell<A>(for:) + 276 (UICollectionView+Extensions.swift:17) 28 SulawesiFishIDApp2024.debug.dylib 0x1013c4940 DetailViewController.collectionView(:cellForItemAt:) + 208 (DetailViewController.swift:327) 29 SulawesiFishIDApp2024.debug.dylib 0x1013c59c8 @objc DetailViewController.collectionView(:cellForItemAt:) + 136 30 UIKitCore 0x1851d521c __112-[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:notify:]_block_invoke.357 + 48 31 UIKitCore 0x18603b5a0 +[UIView(Animation) performWithoutAnimation:] + 68 32 UIKitCore 0x1851d486c -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:notify:] + 1192 33 UIKitCore 0x1851ddf10 -[UICollectionView _createVisibleViewsForSingleCategoryAttributes:limitCreation:fadeForBoundsChange:] + 520 34 UIKitCore 0x1851de478 -[UICollectionView _createVisibleViewsForAttributes:fadeForBoundsChange:notifyLayoutForVisibleCellsPass:] + 288 35 UIKitCore 0x1851dc618 -[UICollectionView _updateVisibleCellsNow:] + 3196 36 UIKitCore 0x1851e1744 -[UICollectionView layoutSubviews] + 284 37 UIKitCore 0x186044bd8 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2404 38 QuartzCore 0x18b0bcfe4 CA::Layer::layout_if_needed(CA::Transaction*) + 432 39 QuartzCore 0x18b0c7d68 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 124 40 QuartzCore 0x18affca50 CA::Context::commit_transaction(CA::Transaction*, double, double*) + 464 41 QuartzCore 0x18b02b260 CA::Transaction::commit() + 652 42 UIKitCore 0x185ad6c3c _UIApplicationFlushCATransaction + 80 43 UIKitCore 0x185a07ccc __setupUpdateSequence_block_invoke_2 + 352 44 UIKitCore 0x18505d28c _UIUpdateSequenceRun + 76 45 UIKitCore 0x185a07670 schedulerStepScheduledMainSection + 168 46 UIKitCore 0x185a06aa8 runloopSourceCallback + 80 47 CoreFoundation 0x18041b7c4 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 24 48 CoreFoundation 0x18041b70c __CFRunLoopDoSource0 + 172 49 CoreFoundation 0x18041ae70 __CFRunLoopDoSources0 + 232 50 CoreFoundation 0x1804153b4 __CFRunLoopRun + 788 51 CoreFoundation 0x180414c24 CFRunLoopRunSpecific + 552 52 GraphicsServices 0x19020ab10 GSEventRunModal + 160 53 UIKitCore 0x185ad82fc -[UIApplication _run] + 796 54 UIKitCore 0x185adc4f4 UIApplicationMain + 124 55 SulawesiFishIDApp2024.debug.dylib 0x10137230c __debug_main_executable_dylib_entry_point + 64 (AppDelegate.swift:13) 56 dyld_sim 0x100c75410 start_sim + 20 57 dyld 0x1009b6274 start + 2840

Thread 1: 0 libsystem_pthread.dylib 0x100b5692c start_wqthread + 0

Thread 2: 0 libsystem_pthread.dylib 0x100b5692c start_wqthread + 0

You should show how and where tableViewData is initialised.

It would help to find which is line 207 in DetailCollectionViewCell.swift:

+ 312 (DetailCollectionViewCell.swift:207) 2 SulawesiFishIDApp2024.debug.dylib 0x1013507cc @objc DetailCollectionViewCell.tableView(_:numberOfRowsInSection:) 


In the Protocol:

protocol DetailCollectionViewCellDelegate: AnyObject {

  func detailCollectionViewCell(_ detailCollectionViewCell: DetailCollectionViewCell, didSelectImageAt index: Int)

  func detailCollectionViewCellDidSelectReefDistributionReport(_ detailCollectionViewCell: DetailCollectionViewCell)

  func detailCollectionViewCellDidSelectFishbase(_ detailCollectionViewCell: DetailCollectionViewCell)
}

You do not call

tableView(_:numberOfRowsInSection:)

But you use it in the extension.

We would need to see the complete code to be sure it is the root cause.

Claude, Many thanks for your help. Here is Line 207:

    guard let tableViewData = tableViewData else { fatalError("no tableViewData") }

I try to paste all the code, but it will not accept it. It turns pink and says "your reply must include text in the body". I will keep trying

I can not post the code. I don't know what the problem is, but you have been a great help and with the information you have given I can probably find a developer who can fix this for me.

Again, many thanks for your time and expertise.

App built with Xcode 16 crashes, worked fine with Xcode 15
 
 
Q