0

I am trying to learn a bit of Swift and xcode by creating a three-level outlineView in the master side of a splitView. The code crashes after exiting to reloadData (see below). It makes one successful pass through the NSOutlineViewDataSource numberOfChildrenOfItem function (I expected a second pass before anything else happened) and then crashes with the "[NSView reloadData]:unrecognized selector sent to instance" error. Here is what is probably the relevant code:

import Cocoa

// import WebKit

class MasterViewController: NSViewController {

@IBOutlet weak var outlineView: NSOutlineView!

var categories = [Category]()

override func viewDidLoad() {
    super.viewDidLoad()

    // Do view setup here.
    if let filePath = Bundle.main.path(forResource: "Subjects", ofType:          "plist"){
        categories = Category.categoryList(filePath)
        print(categories)
    }
    self.outlineView.reloadData()
}

}

//These are extension functions required by a NSOutlineViewDataSource

/* Returns the number of children or grandchildren. One thing to note: item is an optional, and will be nil for the root objects of your data model. In this case, it will be nil for Category; otherwise it will contain the parent of the object. For categoryItem objects, item will be a Category. */

extension MasterViewController: NSOutlineViewDataSource {
func outlineView(_ outlineView: NSOutlineView,
                 numberOfChildrenOfItem item: Any?) -> Int {

    if let category = item as? Category {

        return category.children.count
    }else if let categoryItem = item as? CategoryItem {

        return categoryItem.grandchildren.count
    }

    return categories.count
}

And here is the error dump (I am not knowledgeable enough to make much of this):

[<ProbleMatic.Category: 0x600000048190>, <ProbleMatic.Category: 0x604000049630>, <ProbleMatic.Category: 0x60400004e100>]

2017-12-11 11:16:30.361189-0700 ProbleMatic[11382:4324228] -[NSView reloadData]: unrecognized selector sent to instance 0x6000001237a0

2017-12-11 11:16:30.361701-0700 ProbleMatic[11382:4324228] [General] -[NSView reloadData]: unrecognized selector sent to instance 0x6000001237a0

2017-12-11 11:16:30.365690-0700 ProbleMatic[11382:4324228] [General] (

    0   CoreFoundation                      0x00007fff390b300b
 __exceptionPreprocess + 171

    1   libobjc.A.dylib                     0x00007fff5fc91c76
 objc_exception_throw + 48

    2   CoreFoundation                      0x00007fff3914bcd4
 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132

    3   CoreFoundation                      0x00007fff390293f0
 ___forwarding___ + 1456

    4   CoreFoundation                      0x00007fff39028db8
 _CF_forwarding_prep_0 + 120

    5   ProbleMatic                         0x0000000100001cbc
 _T011ProbleMatic20MasterViewControllerC11viewDidLoadyyF + 1148

    6   ProbleMatic                         0x0000000100001e44
 _T011ProbleMatic20MasterViewControllerC11viewDidLoadyyFTo + 36

    7   AppKit                              0x00007fff3665b632
 -[NSViewController _sendViewDidLoad] + 97

    8   AppKit                              0x00007fff36bffd99
 _noteLoadCompletionForObject + 641

    9   AppKit                              0x00007fff365dfe21
 -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 2042

    10  AppKit                              0x00007fff366db13a
 -[NSNib _instantiateNibWithExternalNameTable:options:] + 679

    11  AppKit                              0x00007fff366dad96
 -[NSNib _instantiateWithOwner:options:topLevelObjects:] + 136

    12  AppKit                              0x00007fff366da06c
 -[NSViewController loadView] + 343

    13  AppKit                              0x00007fff36651f32
 -[NSViewController _loadViewIfRequired] + 75

    14  AppKit                              0x00007fff36651e9d
 -[NSViewController view] + 30

    15  AppKit                              0x00007fff3666c96b
 -[_NSSplitViewItemViewWrapper wrapView] + 94

    16  AppKit                              0x00007fff3666319e
 -[NSSplitViewController _setupSplitView] + 593

    17  AppKit                              0x00007fff36662d15
 -[NSSplitViewController viewDidLoad] + 155

    18  AppKit                              0x00007fff3665b632
 -[NSViewController _sendViewDidLoad] + 97

    19  AppKit                              0x00007fff3665206d
 -[NSViewController _loadViewIfRequired] + 390

    20  AppKit                              0x00007fff36651e9d
 -[NSViewController view] + 30

    21  AppKit                              0x00007fff36aa4cc7
 __67-[NSStoryboardEmbedSegueTemplate newDefaultPerformHandlerForSegue:]_block_invoke + 171

    22  AppKit                              0x00007fff36652015
 -[NSViewController _loadViewIfRequired] + 302

    23  AppKit                              0x00007fff36651e9d
 -[NSViewController view] + 30

    24  AppKit                              0x00007fff36eeaa23
 +[NSWindow windowWithContentViewController:] + 41

    25  AppKit                              0x00007fff3714c44d
 +[NSWindowController windowControllerWithContentViewController:] + 41

    26  AppKit                              0x00007fff36aa4888
 __66-[NSStoryboardShowSegueTemplate newDefaultPerformHandlerForSegue:]_block_invoke + 172

    27  AppKit                              0x00007fff36aa4602
 -[NSStoryboardShowSegueTemplate _perform:] + 275

    28  AppKit                              0x00007fff36da775a
 -[NSApplication(NSResponder) sendAction:to:from:] + 312

    29  AppKit                              0x00007fff3684d933
 -[NSControl sendAction:to:] + 86

    30  AppKit                              0x00007fff3684d85b
 __26-[NSCell _sendActionFrom:]_block_invoke + 136

    31  AppKit                              0x00007fff3684d761
 -[NSCell _sendActionFrom:] + 183

    32  AppKit                              0x00007fff3688ea18
 -[NSButtonCell _sendActionFrom:] + 97

    33  AppKit                              0x00007fff3684bfca
 -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2438

    34  AppKit                              0x00007fff3688e75f
 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 777

    35  AppKit                              0x00007fff3684aa64
 -[NSControl mouseDown:] + 965

    36  AppKit                              0x00007fff36f46959
 -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 5891

    37  AppKit                              0x00007fff36f435b0
 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 2359

    38  AppKit                              0x00007fff36f4285c
 -[NSWindow(NSEventRouting) sendEvent:] + 497

    39  AppKit                              0x00007fff36da3617
 -[NSApplication(NSEvent) sendEvent:] + 307

    40  AppKit                              0x00007fff36604d9d
 -[NSApplication run] + 812

    41  AppKit                              0x00007fff365d3f1a
 NSApplicationMain + 804

    42  ProbleMatic                         0x000000010000f50d
 main + 13

    43  libdyld.dylib                       0x00007fff60881115
 start + 1

    44  ???                                 0x0000000000000003
 0x0 + 3

)

Any suggestions? Thanks in advance.

Palle
  • 11,511
  • 2
  • 40
  • 61
  • The object you are sending this message to is of type NSView, not any subclass. That may be different from how you declared it, or what you think it is, but that's what it is. So your task: Find out why it is an NSView and not what you think it is. – gnasher729 Dec 11 '17 at 19:42

1 Answers1

0

Your outlet is probably connected to something that isn't the outline view (Most likely its superview).

You can check by…

  • Hovering your mouse over the outlet circle
  • or ctrl clicking the outline view in the view hierarchy.

enter image description here

Warren Burton
  • 17,451
  • 3
  • 53
  • 73
  • Yes, that's it. Thank you very much. The problem was building an outlineView inside the splitView. My storyboard showed two "Outline View" entries and I got the outlet hooked to the wrong one. – Black Feather Dec 13 '17 at 17:22