We have a number of UIView subclasses that we load from NIBs. Here's an example of one:
@objc(SwimlaneCell)
public class SwimlaneCell: UITableViewCell {
@IBOutlet private weak var collectionView: UICollectionView!
…
}
I wondered if the @objc(SwimlaneCell) declaration on the front was necessary; I'm pretty sure I've worked on Swift projects with UIView subclasses loaded from NIBs before, and this has not been required.
However, when I try to entirely remove the @objc(SwimlandCell), or reduce it to just @objc (with the class name omitted), then loading the class from a NIB fails. The error is:
Thread 1: "[<UIView 0x7ffbe10b0fd0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key collectionView."
In this case the UIView mentioned is the SwimlaneCell above. collectionView is the property it has that's being injected during loading from a NIB – but here is not being found by the key value mechanisms.
Possibly relevant details:
- This specific cell has had the NIB registered with a
UITableViewand is being loaded as a consequence of a call todequeueReusableCell(withIdentifier:for:). SwimlaneCellis contained in a Swift package along with the table it is used in. The actual app uses the package.
Questions
- Is this always needed and have I imagined not requiring this before?
- If it's not always needed, why might it be needed in this project and what can I do so it is not needed?