Search code examples
cocoanstablerowview

How to initialize NSTableRowView subclass?


The compiler crashses on line 3 and I cant find information on NSTableRowView initializers anywhere

class ItemRowView: NSTableRowView {
    convenience override init(frame: NSRect) {
        self.init(frame: frame) // EXC BAD ACCESS
        self.draggingDestinationFeedbackStyle = NSTableViewDraggingDestinationFeedbackStyle.None
    }

Solution

  • First, init( frame: NSRect )is the designated initializer, so the keyword convenience is wrong in this place. Then you probably meant to call the super initializer than your own method recursively. At last you'll need to implement another required initializer init?(coder: NSCoder)

    The following code should get you going:

    class ItemRowView: NSTableRowView {
        override init(frame: NSRect) {
            super.init(frame: frame) // super - not self
            self.draggingDestinationFeedbackStyle = NSTableViewDraggingDestinationFeedbackStyle.None
        }
    
        required init?(coder: NSCoder) {
            // Write something useful here, or leave the default implementation
            fatalError("init(coder:) has not been implemented")
        }
    }