У меня есть пользовательский класс элементов
class AttachmentCell: NSCollectionViewItem {
override func viewDidLoad() {
super.viewDidLoad()
// Do view setup here.
}
}
, который я пытаюсь создать в делегате как
func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
let item = collectionView
.makeItem(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "AttachmentCell"),
for: indexPath) as! AttachmentCell
return item
}
Теперь программа вылетает с ошибкой
Could not cast value of type 'NSCollectionViewItem' (0x7fffa5050690) to 'Notes.AttachmentCell' (0x10000ee38).
2019-06-04 13:01:33.603441+0200 Notes[18477:37049533] Could not cast value of type 'NSCollectionViewItem' (0x7fffa5050690) to 'Notes.AttachmentCell' (0x10000ee38).
Насколько я понимаю, makeItem должен дать мне объект того типа, который я ему дал (и я думаю, что я видел эту работу раньше), поэтому я понятия не имею, что здесь происходит.