Error: Could not load NIB in bundle: 'NSBundle
If your app builds, but then crashes when you try to load a particular view, chances are you've forgotten a simple step.
This happens when you are using .xib
files along with code. For me, I'm using a programatic table view, with .xib
s.
This the full error message:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle <long path name/AppName.app> (loaded)' with name '<Name of the nib>''
Some things to check:
- You have registered the nib:
tableView.register(UINib(nibName: T.dequeueIdentifier, bundle: nil), forCellReuseIdentifier: T.dequeueIdentifier)
- The
fileName.xib
is exactly the same as the name you used to register. This is where I tripped up. I was usingnibName: ListStandardIconCell
, but my file name wasListStandardIcon.xib
. When I changed it toListStandardIconCell.xib
, the crash went away. - Have a
.swift
file that is associated to the nib, so that you can drag in the outlets
import UIKit
// MARK: - ListStandardIconCell
final class ListStandardIconCell: UITableViewCell {
// MARK: Outlets
@IBOutlet private weak var titleLabel: UILabel!
@IBOutlet private weak var iconImageView: UIImageView!
}
- The custom class is set to the associated
.swift
for that nib (see image below)