Reputation: 236
I have a collection view that has a horizontal flow layout. After scrolling through about 4 to 5 cells, the code crashes with a SIGABRT error message that I can't find anywhere else online.
Assertion failure in void _removeFromEngineVarTable(NSISEngineVar)(), /BuildRoot/Library/Caches/com.apple.xbs/Sources/Foundation/Foundation-1562/Foundation/Layout.subproj/IncrementalSimplex/NSISEngine.m:1518
Here is the code for the cellForItem:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "listingCell", for: indexPath) as? ListingCollectionViewCell {
cell.listing = listings[indexPath.item]
cell.segmentedControl.removeAllSegments()
cell.listing.termContracts.forEach {
var title = ""
switch $0.availableFor {
case "Fall": title = "Fa"
case "Fall/Winter": title = "Fw"
case "Winter": title = "Wi"
case "Spring": title = "Sp"
case "Spring/Summer": title = "Ss"
case "Summer": title = "Su"
case "Year Round": title = "Year"
default: title = ""
}
cell.segmentedControl.insertSegment(withTitle: title, at: cell.segmentedControl.numberOfSegments, animated: false)
}
cell.contactLabel.text = cell.listing.contactPhone
cell.contactPersonLabel.text = cell.listing.contactPerson
cell.addressLabel.text = cell.listing.address
//Default data to first contract
if cell.listing.termContracts.isEmpty {
cell.rentLabel.text = "N/A"
cell.sharedPrivateLabel.text = ""
} else {
if let rent = cell.listing.termContracts[0].rent {
cell.rentLabel.text = rent == 0 ? "Free" : "$\(rent)/mo"
}
if let sharedPrivate = cell.listing.termContracts[0].sharedPrivate {
cell.sharedPrivateLabel.text = sharedPrivate
}
}
cell.segmentedControl.selectedSegmentIndex = 0
return cell
}
return UICollectionViewCell()
}
The problem is in this line:
if let rent = cell.listing.termContracts[0].rent {
cell.rentLabel.text = rent == 0 ? "Free" : "$\(rent)/mo"
}
When I replace this with
if let rent = cell.listing.termContracts[0].rent {
cell.rentLabel.text = rent == 0 ? "Free" : "$\(cell.listing.termContracts[0].rent)"
}
It works perfectly fine. But because rent is optional, I get the ugly "Optional(___)" when it renders out. Is this a bug?? I don't see any reason for anything to break, because I'm handling everything safely. I also don't see any fundamental differences between if letting rent and just throwing it in there.
The collection view also crashes when I make it scroll to a specific index, which makes me think that it's a reusable issue?
EDIT: IB details
Upvotes: 3
Views: 1108
Reputation: 236
I added a fixed width constraint to the uiLabel, and it stopped crashing. Thanks to @Matt the Legend for helping me figure this one out!
Upvotes: 1
Reputation: 535989
You have an autolayout issue. NSISEngine is the autolayout "solver". You have not described your interface so it's impossible to help more precisely, but there must be something difficult or time-consuming to solve in your autolayout constraints (inequalities perhaps? lowered priorities?), and it is probably the constraints on rentLabel
or something connected to it (or the layout-determining properties of rentLabel
).
Start by simplifying the layout of this label, even this gives the "wrong" interface, and see if you can make the problem go away. If you can, try to restore your constraints in a more efficient way.
Upvotes: 2