DragNDrop doesn't work properly in NSBox

Hi. I have a Swift macOS app in Xcode 12. I have created NSBox subclass to implement drag-and-drop. When I add NSBox in Storyboard and set its class to my custom class, everything works. However, when I try to add this class to NSViewController programatically, like this:
Code Block
let box = EditCard()
let button = NSTextField()
let text = NSTextView.scrollableTextView()
        
let frame_box = NSRect(x: 17, y: 118, width: 320, height: 260)
let frame_scroll = NSRect(x: 8, y: 10, width: 20, height: 20)
let frame_button = NSRect(x: 8, y: 204, width: 300, height: 32)
box.borderColor = .black
box.cornerRadius = 18
box.fillColor = .black
box.frame = frame_box
box.titlePosition = .noTitle
box.boxType = .custom
box.borderWidth = 0.5
button.isEditable = true
button.isSelectable = true
button.refusesFirstResponder = true
button.focusRingType = .none
button.frame = frame_button
button.isBordered = false
button.alignment = .center
button.backgroundColor = NSColor(calibratedWhite: 0.0, alpha: 0.0)
button.font = .boldSystemFont(ofSize: 23)
button.textColor = .textColor
text.drawsBackground = false
text.frame = frame_scroll
(text.contentView.documentView as! NSTextView).font = .systemFont(ofSize: 12)
(text.contentView.documentView as! NSTextView).isEditable = true
(text.contentView.documentView as! NSTextView).isSelectable = true
box.addSubview(button)
box.addSubview(text)
view.addSubview(box)

it doesn't work properly. I can drag this view, but if I try to drop it on another similar view of the same class, none of the DragDestination functions run. Can somebody tell me what I am doing wrong?